0

Problem Statement: I have been facing the issue for selecting following web element. (Actually these are the texts)

HTML Code:

 <tr class="inputtextfields" bgcolor="#CDDBE9"> <td width="12%" height="25"> <div align="center">Firstname1234Lastname</div></td> <tr class="inputtextfields" bgcolor="#CDDBE9"> <td width="12%" height="25"> <div align="center">Firstname45671Lastname</div></td> 

What am I looking for?

I am looking for the locating "Firstname1234Lastname" element or text by Web Driver using Java language. Your help is highly appreciated.

4
  • share your code and specify problems you've faced with your code Commented Mar 16, 2017 at 8:45
  • I am using the absolute XPATH to select the element and it's working fine but as we all aware of we should be using 'Relative XPATH' or something better and unique. If the structure of the web page changes then my absolute xpath will not work. I am looking for help to build relative xpath. Commented Mar 16, 2017 at 8:48
  • It's hard to suggest good selector with provided HTML sample. Can you share more ancestors? Commented Mar 16, 2017 at 8:55
  • I have updated the code. Now I want to select "Firstname1234Lastname". How do I do that? Commented Mar 16, 2017 at 9:03

1 Answer 1

1

You can try below XPath to locate required elements:

"(//tr[@class='inputtextfields']/td/div)[1]" // For "Firstname1234Lastname" 

and

"(//tr[@class='inputtextfields']/td/div)[2]" // For "Firstname45671Lastname" 
Sign up to request clarification or add additional context in comments.

1 Comment

Please mark this answer as Accepted if it solved your issue. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.