1

I have to click on first link in the table. Not able to click the link, it's id and xpath is changing when a new record is created as follows :

Action  Exception Number                        
Edit | Del  EX-0000529

Edit | Del  EX-0000528

Edit | Del  EX-0000527

Edit | Del  EX-0000526

Edit | Del  EX-0000525

HTML is as follows :

 <td class="x-grid3-col x-grid3-cell x-grid3-td-NAME " tabindex="0" 
 style="width:251px;">
 <div id="a3h290000001fC6_NAME" class="x-grid3-cell-inner x-grid3-col-NAME">
 <a href="/a3h290000001fC6">
 <span>EX-0000529</span>
 </a>
 </div>
 </td>
 <td class="x-grid3-col x-grid3-cell x-grid3-td-NAME " tabindex="0" 
  style="width:251px;">
  <div id="a3h290000001f9v_NAME" class="x-grid3-cell-inner x-grid3-col-
  NAME">
  <a href="/a3h290000001f9v">
  <span>EX-0000528</span>
  </a>
  </div>
  </td>
1
  • Please clarify your description above the code sample. Commented Dec 6, 2017 at 14:28

2 Answers 2

1

The provided html shows the table element you want to click is having a link. So First get all the links and then you can click on your desired link by index.

below is the sample code yo can workwith.

java.util.List<WebElement> links = driver.findElements(By.tagName("a"));
System.out.println(links.size());
for (WebElement elem : links)
{
    elem.click();
}

If you just want to click on the first link then just use below line instead of for loop.

links.get(0).click();
Sign up to request clarification or add additional context in comments.

1 Comment

And if OP wants to click only first element, instead of using for loop, he can just use links.get(0).click(); :)
0

To click on first link in the table i.e. EX-0000529 you can use the following line of code :

driver.findElement(By.xpath("//td[@class='x-grid3-col x-grid3-cell x-grid3-td-NAME']//following::span[1]")).click();

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.