Skip to content

Instantly share code, notes, and snippets.

@seleniumgists
Created November 13, 2020 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seleniumgists/a97f785397547bdd0793d70207344d8a to your computer and use it in GitHub Desktop.
Save seleniumgists/a97f785397547bdd0793d70207344d8a to your computer and use it in GitHub Desktop.
generated automatically from #selenium on seleniumhq slack
<documentRoot>
<!-- Test data -->
<?value="2"?>
<parent name="data" >
<child id="1" name="alpha" >Some Text</child>
<child id="2" name="beta" >
<grandchild id="2.1" name="beta-alpha" ></grandchild>
<grandchild id="2.2" name="beta-beta" ></grandchild>
</child>
<pet name="tigger" type="cat" >
<data>
<birthday month="sept" day="19" ></birthday>
<food name="Acme Cat Food" ></food>
</data>
</pet>
<pet name="Fido" type="dog" >
<description>
Large dog!
</description>
<data>
<birthday month="feb" day="3" ></birthday>
<food name="Acme Dog Food" ></food>
</data>
</pet>
</parent>
</documentRoot>```
This are my statements
```SelenideElement parent = $(By.xpath(//parent[@name = 'data'])
SelenideElement pet = parent.$(By.xpath(.//pet[@name='Fido'])```
I try to get the element "parent" and then search for child element from the variable "parent".
But I get -> `NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//pet[@name='Fido']}`
But when I execute
```SelenideElement pet = parent.$(By.xpath(//parent[@name = 'data']//pet[@name='Fido'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment