简体   繁体   English

硒的webdriver - 存储多个linktext的的

[英]Selenium Webdriver - Store multiple linktext's

I'm automating a web application using Selenium Webdriver(Java), but having difficulty in storing multiple linktext's. 我正在使用Selenium Webdriver(Java)自动化Web应用程序,但是很难存储多个linktext。 Below is my html code, I have to fetch all email id's to verify before inserting new one. 以下是我的html代码,在插入新的电子邮件ID之前,我必须先获取所有电子邮件ID进行验证。

<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. 同样,它具有大约20个linktext(电子邮件ID),并且需要存储这些电子邮件ID以进行验证。

Any help would be greatly appreciated 任何帮助将不胜感激

  1. I would try to find the table and store it inside WebElement variable. 我会尝试查找表并将其存储在WebElement变量中。 Lets call the variable table 让我们调用变量table
  2. Then, inside the table try to call List<WebElement> emails = table.findElements(By.partialLinkText("0")); 然后,在表内尝试调用List<WebElement> emails = table.findElements(By.partialLinkText("0"));
  3. All emails should be stored here, in form of WebElement classes 所有电子邮件都应以WebElement类的形式存储在此处
  4. to get the mail in readable form you can call getText on each of item from the list 要以可读的形式获取邮件,可以在列表中的每个项目上调用getText

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()); 
 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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