开发者

selenium can't find the element

I'm testing my webapp using selenium webdriver, but the driver can't fi开发者_开发技巧nd my element, the element's style is set to display:none visible,and I'm using xpath to retrieve that element here is my xpath

By.XPath(".//*[@id='box']/table/tbody/tr[3]/td[4]")

Please advise.

Many thanks


the tbody looks suspicious to me. This is often implicitly inserted by some browsers. I don't know anyone who uses it in html.

Therefore, you could try an XPath without it:

By.XPath("//*[@id='box']/table/tr[3]/td[4]")

If this doesn't help: Could you add an (X)HTML snippet?


Remove that leading dot:

By.XPath("//*[@id='box']/table/tbody/tr[3]/td[4]")


Maybe, for debugging reasons (and maybe not only for that) you should split up your xpath. For example (in pseudo-python):

tables = driver.findElementsByXPath("//*[@id='box']/table")
if len(tables) == 0:
   break

trs = tables[0].findElementsByXPath("/tr")
if len(trs) == 0:
   break

tds = trs[3].findElementsByXPath("/td") # or maybe trs[2]
if len(tds) == 0:
   break

td = tds[4] # or maybe tds[3]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜