I have a Test which search for <span class="legend">
. On a previous level I have a fieldset which contains several values. Here is my problem. I don't get the locator for this fieldset.
First of all I get a list with all class=legend
objects:
List<WebElement> groupList = driver.findElements(By.className("legend"));
This works perfectly, I have a list with several Webelements.
Now I want to iterate this list and save every value from the fieldset of the previous level only. The problem is that Selenium does not find the id of the fieldset.
I tried tempGroupElement.getAttribute("id")
to get the id but it does not work.
Any idea?
First of all we have to identify the known element with the help of any of the locators like id, classname and so on. Then we have to identify its parent element with findElement(By. xpath()) method. Also we can identify the parent element of a known element with the help of Javascript Executor.
Start by writing out the selenium Xpath for the parent and then traverse to desired object using back slashes like so; Xpath Parent written as //div[@class='region region-navigation' using our previously shown syntax. Now you start to traverse through the HTML nodes down to desired object.
We can perform double click on elements in Selenium with the help of Actions class. In order to perform the double click action we will use moveToElement() method, then use doubleClick() method. Finally use build().
I have a method for this in C#.
public static IWebElement GetParent(IWebElement e) { return e.FindElement(By.XPath("..")); }
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With