I have a document with all the html that I want to manipulate but its all over the place.
I can get it fairly tidy using
Elements paragraphs = document.select("p");
But its not the format that I want it in.
For example if its a table that I want to organise how do I just say take in the first set of elements eg(everything on a particular day monday) then everything on tuesday...
Im not sure how to select it correctly. As I want to put the txt into arraylists of class type.
In the html each set of info I want starts with td and ends with /td
So how do I select the first td then the second one then the third one etc.
Thanks for the help.
I am not sure, that I understand your porblem correctly and since I can't comment I am posting it as an answer.
You can select all of your td's and then get their childs
$('td').children('li').each(function(index, element) {
and add them to your array here
});
Related
I am working on this grid, using SELENIUM & JAVA and chromedriver.
Take a look at this and it's behaviour (it is a .gif):
When i need to add a new row to that grid i have to click on
"ADD OPTION" and then a new row is inserted
The problem is that i do not understand how to pass a collection of values, i want to achieve this:
I want to pass a collection and my program should place them in the grid (2 values each row) without getting the xpath of every single box. I need to make it more efficient.
Example: i have this collection:
["fdfdfddf","989"; "RERE","6655"; "HEHE","554"; "TTER","89"]
I want my program to place them in the GRID.
Desired result:
The problem is that in my code i do need to know the xpath of each "box" of the grid in order to insert data.
This is my code to add data to the grid:
driver.findElement(By.id("add_new_option_button")).click(); //it clicks on "Add Option" button
driver.findElement(By.xpath("//*[#id=\"manage-options-panel\"]/table/tbody/tr[40]/td[3]/input")).sendKeys("fdfdfddf");
driver.findElement(By.xpath("//*[#id=\"manage-options-panel\"]/table/tbody/tr[40]/td[5]/input")).sendKeys("989");
driver.findElement(By.id("add_new_option_button")).click();
How can i fill in the boxes without knowing the xpath of every box?
I don't want to click on every box of each row to get the xpath, i need to find another fast solution.
This is how i get the xpath of every box:
You can solve this by using xpath like.
Xpath=//*[#type='text']//following::input
Here First target a element which is just before your input box then when you add any new box then the xpath will like
Xpath=//*[#type='text']//following::input[1]
Xpath=//*[#type='text']//following::input[2]
Xpath=//*[#type='text']//following::input[3]
Now you can run a loop or otherway and input value inside the box without taking different xpath
I am working on a testing program that operates with very little information. In this particular case, my program doesn't know the ID of elements in the page before it runs, because the Javascript on the page dynamically assigns those at run time. The only constants I have is the structure and the text I'm looking for. I'm including a screenshot of one example of the DOM being generated. In this case I know that I want to access the button with text apply that is displayed next to the label with the text "To Location:" Is there a way to use xpath manipulate their relationship and ensure that I'm accessing the right element. I can't just access the apply button because there are 6 apply buttons on the page with dynamically generated IDs. The label's next to them are different so I'm trying to use that and manipulate the path's from there. Help?
This is possible. If you provide the entire html code I could provide a better xpath. But for what you pasted, here's a simple one that might work:
//td[div//label[text()='To Location:']]/following-sibling::td[1]//button[text()='Apply']
There's a slightly longer winded way but thats generating a list of elements by class and clicking the one with the right text
`var elements = driver.FindElements(By.Class("text-pb"));
foreach(var element in elements)
{
if(element.Text.Equals("Searched Text"))
{
element.click();
}
}`
that might work thats if you want to click the button.
i use these sort of things on the pages works site generates so it should do what your after.
I have two buttons on a page that have really similar xpaths -
the button im trying to click -
/html/body/div[#id='wrapper']/div[#id='content']/div[#id='contentarea']/div[#id='votecontent']/div[#id='votetext']/div[#id='voteboxes']/div[#id='votenow'][2]/form/input[2]
and the other button im trying to ignore -
/html/body/div[#id='wrapper']/div[#id='content']/div[#id='contentarea']/div[#id='votecontent']/div[#id='votetext']/div[#id='voteboxes']/div[#id='votenow'][1]/form/input[2]
the only difference between the two is the
[#id='votenow'][1]
and
[#id='votenow'][2]
but I can't figure out how to interact with the one that has the votenow[2], whichever way I go about it, it always seems to interact with the first one because that's the first one it finds
this is for java using the firefox driver, any suggestions would be great :)
Just find them both and get the desired one by index:
List<WebElement> buttons = driver.findElements(By.xpath("your xpath"));
WebElement secondButton = buttons.get(1);
First
Please talk to your developers! It is really bad practice to assign the same id to two different elements (in your case buttons) on the same page! It makes life for DEV and QA unnecessarily harder than it need be!
Second
The xpath-expressions you posted already contain the differentiation between these two buttons. So you just need to find the first one and click it.
via xpath:
You can use xpath - should be enough to search for the elements with id="votenow". As said before, you can be pretty precise in this case and already filter for the 2nd button:
WebElement button02 = driver.findElement(By.xpath("//div[#id='votenow'][2]/form/input[2]"));
button02.click();
via id:
As #alecxe already pointed out, you can also first go for a more general search of several elements and then filter the right one out. Personally I would use the id in this case:
List<WebElement> buttonWrappers = driver.findElements(By.id("votenow"));
// you want the button-input-element in the 2nd wrapper element, indexing starts at 0, so do this:
WebElement button02 = buttonWrappers.get(1).findElement(By.xpath("//input[2]"));
// since it seems there are several input elements below the desired div, you can use xpath again
how do I get the xpath or css or ANYthing to click this ok button??? Problem is these ids and other attributes have tags that are changed every time a user goes to this particular page
--ea3b2e21-3847-47de-860c-3596695fbb35-- so i don't know what to do
Ok
All you can do here is try and find some part of the element that does not change. If you can add some sample html it would help.
Have you read the
docs for dynamic elements?
just as we select tags before posting a question on stack overflow, I wanted to do something similar when registering a contact into database. In the form, there is a JTextField txtTags which asks for a word to best describe a contact. i.e. Contact John Smith is best described by java. java becomes the tag.
My confusion lies in in multiple tags being created for a contact where I need to display a list of tags before adding to database. It would be great just like stackoverflow post questions tags part allows to remove the tag if you make a mistake.
So just below the text field, I would like to display all the tags.
Please can you show me how to go about with the logic.
I am using java reflector field, so DTOs and DAOs. In the DTO, how would the tag field setter and getter logic work, I think something to do with list.
I would appreciate a sample to code to demonstrate the ideas. arraylist, list, collections anything. :)
You can get text from the textfield. Split it to have array of tag names (in fact String[]). For each tag name in the array you should check your list of existing tags and figure out whether there is a tag for each tag name.
For the found ones you can show a popup or something... or throw an error when some tag is not found.
create JDialog contains JTable in JScrollPane (maybe not requied, but then you have to restrict number of visible rows, maybe bad idea, maybe not)
have to decide about numbers of column, (2- 4 columns???), maybe to remove showHorizontalLines, showVerticalLines, then you'll the same autocomplete as you wanted
put there (to the JDialog) JTextField and to use Filtering in JTable, everything is encoded in the example JTable from tutorial TableFilterDemo