简体   繁体   中英

Selenium Webdriver - Store multiple linktext's

I'm automating a web application using Selenium Webdriver(Java), but having difficulty in storing multiple linktext's. Below is my html code, I have to fetch all email id's to verify before inserting new one.

<tr class="odd" >
      <td><input type="radio" name="item" value="52"></td>
      <td><a href="/Abcdef/UpdateAction.do?userno=52">abcd.xyz@abc.com</a></td>
      <td>Abcd Xyz</td>
      <td>internal</td>
</tr>
<tr class="even" >
      <td><input type="radio" name="item" value="151"></td>
      <td><a href="/Abcdef/UpdateAction.do?userno=151">klmn.opqr@abc.com</a></td>
      <td>Klmn Opqr</td>
      <td>internal</td>

. .

Likewise it has around 20 linktext's(email id's) and those email id's need to be stored for verification.

Any help would be greatly appreciated

  1. I would try to find the table and store it inside WebElement variable. Lets call the variable table
  2. Then, inside the table try to call List<WebElement> emails = table.findElements(By.partialLinkText("0"));
  3. All emails should be stored here, in form of WebElement classes
  4. to get the mail in readable form you can call getText on each of item from the list

Thanks for your earlier reply.

I used below code to print all linktext's with in table.

 WebElement table = driver.findElement(By.id("table_id"));
 List<WebElement> emails = table.findElements(By.tagName("a")); 
 for(WebElement tdElement : emails) { 
 System.out.println(tdElement.getText()); 
 } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM