vendredi 8 juillet 2016

XPATH descendant path with attribute

I have a bit of a complicated query; I am using XPath and Selenium in Java to attempt to access a certain div on the page:

By.xpath("li/div[div[contains(@class, 'class1')]/div[text() = 'string1']]/div[position() = 3 and contains(@class, 'class2') and contains(@class, 'class3')]")

Basically, I am trying to do the following:

  • Access a div with xpath "li/div/div[position() = 3 and contains(@class, 'class2')] and contains(@class, 'class3')"] (get the 3rd grandchild of <li> with certain classses), where
  • The child div in "li/div" has a child with class 'class1', which in turn has a child containing the text 'string1'.

I am getting syntax errors on this, however, and I am not sure what the issue is. I have checked the xpath query and there doesn't seem to be any grammatical issues with it.

Aucun commentaire:

Enregistrer un commentaire