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

后端 未结 5 1118
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  悲哀的现实
    2021-01-11 13:09

    I also ran into this issue and spent quite a lot of time trying to figure out the workaround. And this is what I figured out:

    WebElement td = tr.findElement(By.xpath("td[3]"));
    

    Not sure why, but this works for me.

提交回复
热议问题