Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium find child's child elements

I have following html like:

<form name="form1">
  <input name="a" ...>
  <input name="b" ...>
  ...
  <div><span><select name="c">...</select></span></div>
</form>

I would like to find out all elements within the form element. First I use findElement() to get the form element form1, then use form1.findElements(By.xpath(".//*[@name]")) to get all its children having attribute name. However, for the select element, since it's grand-grand child of form1, how can I get it as well?

Is there a way to find all elements containing attribute name (not only child elements, but also child's child's child...) within form1?

Thanks!

like image 817
Eve Avatar asked Nov 26 '13 12:11

Eve


1 Answers

if you want to get an WebElement by xpath, and so get child of it... you may use webElement.findElement(By.xpath("./*")) ... this "." before the "/" makes the magic, you'll need it to get only the children of the webElement...

like image 176
Alan Donizete Avatar answered Dec 10 '22 13:12

Alan Donizete