Hi. I have a situation where i have to capture all the elements in a webpage based on the xpath i provide. Example- we have 10 rows and 10 columns. Column 5 of each row has the price listed. I want to capture all the prices in a list based on the xpath. In selenium it is easy since as below. Do we have a similar method as "findElements" based on xpath:
List<WebElement> grossPrice = driver.findElements(By.xpath("//td[@class='sorting_1']"));.
Get all elements using xpath
Re: Get all elements using xpath
Hi,
Please post a Ranorex snapshot of the element in question so we can better understand your GUI and provide reasonable suggestion. Without snapshot, it's much harder to give correct answer.
Please post a Ranorex snapshot of the element in question so we can better understand your GUI and provide reasonable suggestion. Without snapshot, it's much harder to give correct answer.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Re: Get all elements using xpath
Just for your info: Even without seeing a snapshot, you can search for all elements matching a RanoreXPath using the Find method, e.g.:
Just make sure to use a relative path (precede it with a dot ".") to search from the "searchRoot" element, which can be the DOM or any web element underneath it.
Regards,
Alex
Ranorex Team
IList<WebElement> webElements = searchRoot.Find<WebElement>(".//td[@class='sorting_1']"); // or if you want elements of type TdTag IList<TdTag> tdTags= searchRoot.Find<TdTag>(".//td[@class='sorting_1']");Using the TdTag type provides a few more properties on each element than using the generic WebElement type (see the API doc).
Just make sure to use a relative path (precede it with a dot ".") to search from the "searchRoot" element, which can be the DOM or any web element underneath it.
Regards,
Alex
Ranorex Team
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Get all elements using xpath
Hi Team. I could not get which element should be specified under "searchRoot". I am attaching a snapshot for ref. basically i am looking at getting all the values under Power column. Highlighted value of 9.8 is for First row alone. A reputation of multiple rows with the same structure (as of row-1) is continued for other values of Power.
- Attachments
-
- Snapshot.jpg (234.41 KiB) Viewed 4381 times
Re: Get all elements using xpath
Hi,
What you have posted is unfortunately not snapshot, but screenshot, which is unfortunately not helpful. Please learn how to create one here...
http://www.ranorex.com/support/user-gui ... files.html
What you have posted is unfortunately not snapshot, but screenshot, which is unfortunately not helpful. Please learn how to create one here...
http://www.ranorex.com/support/user-gui ... files.html
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Get all elements using xpath
Get that. Please find attached
- Attachments
-
- Snapshot.rxsnp
- (265.47 KiB) Downloaded 89 times
Re: Get all elements using xpath
Thanks for the snapshot. OK, because there is no unique Id for individual cells belonging to the Capacity column (in your previous screenshot called 'Power'), there is no way to get all elements belonging to this column directly via a simple xpath.
What you need to do is to get the "ChildIndex" value for column 'Capacity' and store it in a variable. You can do this via GetValue recording action/method, referring to this xpath:
Then you need to create a new repo item (let's call it ListofTDTags) where the $childIndexVar is the variable obtained via GetValue action...
This repo item returns all TD tags under "Capacity [kW]" column.
Now you can create iList of TdTag adapters from this repo item...
Hope this helps?
BTW, some time ago, I've posted a suggestion for a new HTML table relationship operators, allowing us to get cells, based of row/column relationship. This would solve our problem with HTML tables. Please vote for it here...
http://uservoice.ranorex.com/forums/150 ... -html-cell
What you need to do is to get the "ChildIndex" value for column 'Capacity' and store it in a variable. You can do this via GetValue recording action/method, referring to this xpath:
Code: Select all
/dom[@domain='sv42080oel8128']//table[#'resultList']/thead/tr/td[@innertext='Capacity [kW]']
Code: Select all
/dom[@domain='sv42080oel8128']//table[#'resultList']/tbody/tr/td[@childindex=$childIndexVar]
Now you can create iList of TdTag adapters from this repo item...
Code: Select all
IList<TdTag> tdList =
repo.ListofTDTagsInfo.CreateAdapters<TdTag>();
BTW, some time ago, I've posted a suggestion for a new HTML table relationship operators, allowing us to get cells, based of row/column relationship. This would solve our problem with HTML tables. Please vote for it here...
http://uservoice.ranorex.com/forums/150 ... -html-cell
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
Ranorex explorer at Descartes Systems
Please add these details to your questions:
- Ranorex Snapshot. Learn how to create one >here<
- Ranorex xPath of problematic element(s)
- Ranorex version
- OS version
- HW configuration
-
- Posts: 56
- Joined: Wed Jun 10, 2015 4:35 pm
Re: Get all elements using xpath
Perfect. Worked exactly the way you suggested. Thank you 
