2

I'm testing my webapp using selenium webdriver, but the driver can't find 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

1
  • 1
    can you please add an html snippet of the area you're looking for. Plus, what driver you're using - i.e., HtmlUnit, Firefox, Chrome..? Commented Jul 18, 2011 at 9:21

3 Answers 3

1

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?

Sign up to request clarification or add additional context in comments.

Comments

0

Remove that leading dot:

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

1 Comment

Still failing, the By.XPath is giving me an empty string. The tr[3] element is invisible which is the style is in display:none. But I'm not use if that is that problem.
0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.