selenium find child's child elements selenium find child's child elements selenium selenium

selenium find child's child elements


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...


Do you have to find the form element? If not, then you can do it in one select statement using css or xpath.

The css would be 'form[name="form1"] [name]'

Note the space between the closing and opening brackets.

You would use this selector with FindElement on the driver object rather than finding the form first.


You should be able to use the descendant:: as described in this post.

http://hedleyproctor.com/2011/05/tutorial-writing-xpath-selectors-for-selenium-tests/

Here are a few examples from the article:

//div[h3/text()='Credit Card']/descendant::*//div[h3/text()='Credit Card']/descendant::input[@id='cardNumber']//div[*/text()='Credit Card']/descendant::input[@id='cardNumber']  webDriver.findElement(     By.xpath("//div[*/text()='Credit Card']/descendant::input[@id='cardNumber']")  ).sendKeys("1234123412341234");