2

I am trying to read and click a value in a row (row width=85) of table using Selenium. So far I tried these two methods, but unable to locate value. I am attaching html code as image.

findElementByXpath("//table/tbody/tr[2]/td[2]");

findElementByXpath("//table[@width=\"85\"]/tbody/tr[2]/td[2]");

table html code

Any help, really appreciated.

1 Answer 1

2

Rely on the id attributes to get the table element and get the first td with width="85"inside:

findElementByXpath('//div[@id="Display"]/table[@id="tblData"]//td[@width="85"]')

Note that relying on the width attribute doesn't seem very reliable. Alternatively, use indexes - get the second td in the first tr tag inside the table (indexing starts from 1):

findElementByXpath('//div[@id="Display"]/table[@id="tblData"]//tr[1]/td[2]')
Sign up to request clarification or add additional context in comments.

2 Comments

alecxe, thank you for the help, a slight change in Xpath worked. findkElementByXpath("//div[@id=\"Display\"]/table[@id=\"tblData\"]//tr[2]/td[2]"); or findElementByXpath("//div[@id=\"Display\"]/table[@id=\"tblData\"]//td[@width=\"85\"]");
You can also try out like: findElementByXpath(//table[@id='tblData']//td[contains(text(),'<your text>')])

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.