2

A table has 2 or more rows (depending on previous action) and the contents are not ordered. One of the column has unique elements. I need to select the row depending on the unique element using selenium webdriver (java). I am passing the locators using an excel sheet.

For eg, I have the following kind of table:


Select Name Id

Radio_button ABC Id1

Radio_button ABC Id2

Suppose for the above table, the order of the rows are not same all the time and depending on id value, I need to select the correct radio button. How do I identify the correct radio button depending on the id value?

2 Answers 2

0

Use xpath for finding your element:

//tr[*[@id='id1']]//input

This is a locator for Radio_button that is in the same row as id1. If you provide your html code of the table, the answer will be more precisely, but the general idea is clear, I suppose.

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

Comments

0

Though the selenium doesnt give any error for the xpath (verifyVisible), which you had mentioned , am not able to click/check on that particular radio button.

It identifies only the first radio button and checks on that.

4 Comments

Problem got solved with the xpath //td[contains(text(),'id1')]/../td[1]/input
Of course it will identify not your actual radiobutton as you didn't provide any code. In my xpath you should just replace @id with text() and it will work too: //tr[*[contains(text(),'id1')]]//input. Also use add comment instead of Add another answer if you want to reply on somebody's answer.
Thanks a lot!!! This path is also working fine. Ok..sure! I will comment from now on when I want to reply.

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.