Selenium 2 - Can findElement(By.xpath) be scoped to a particular element?

后端 未结 5 1212
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 12:21

All the examples of findElement(By.xpath) I\'ve seen search the whole page, e.g.

WebElement td = driver.findElement(By.xpath(\"//td[3]\"));

5条回答
  •  萌比男神i
    2021-01-11 13:10

    Based on ZzZ's answer I think the issue is that the queries you are trying are absolute instead of relative. By using a starting / you force absolute search. Instead use the tag name as ZzZ suggested, ./ or .//.

    Look in the XPath docs under "Location Path Expression"

提交回复
热议问题