Java 在我的网站的表格中搜索文本-使用我的selenium代码

Java 在我的网站的表格中搜索文本-使用我的selenium代码,java,xpath,selenium,webdriver,selenium-webdriver,Java,Xpath,Selenium,Webdriver,Selenium Webdriver,我创建了一个selenium代码,用于在我的网站中自动化测试 在一个屏幕中,我运行一个查询,系统在IE屏幕中以表格的形式显示该查询的结果 然后我需要选择并单击这个表中的一行 我尝试使用下面的代码来实现这一点,但是Eclipse中的结果是它找不到元素0531025836,即使它出现在我屏幕上的结果表中 driver.findElement(By.xpath("//td[contains(.,'0531025836')]")).click(); 我以前从未见过XPath(但与这里的一些人相比,我对

我创建了一个selenium代码,用于在我的网站中自动化测试

在一个屏幕中,我运行一个查询,系统在IE屏幕中以表格的形式显示该查询的结果

然后我需要选择并单击这个表中的一行

我尝试使用下面的代码来实现这一点,但是Eclipse中的结果是它找不到元素0531025836,即使它出现在我屏幕上的结果表中

driver.findElement(By.xpath("//td[contains(.,'0531025836')]")).click();

我以前从未见过XPath(但与这里的一些人相比,我对XPath不是很精通)

如果您正在寻找一条语句来选择正好包含该文本的元素,请尝试
//td[.='0531025836']


如果您正在寻找一条语句来选择包含该文本的元素,请尝试
//td[contains(text(),'0531025836')]

根据我的理解,您正在处理webTables。如果我是正确的,那么你可以在谷歌上找到多个例子,比如下面给出的例子

WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://money.rediff.com/");

WebElement element=driver.findElement(By.id("allpage_links"));
List<WebElement> rowCollection=element.findElements(By.xpath("//*[@id='allpage_links']/tbody/tr"));


System.out.println("Number of rows in this table: "+rowCollection.size());
//Here i_RowNum and i_ColNum, i am using to indicate Row and Column numbers. It may or may not be required in real-time Test Cases.       
int i_RowNum=1;
for(WebElement rowElement:rowCollection)
{
      List<WebElement> colCollection=rowElement.findElements(By.xpath("td"));
      //now here you have list of webelements of the table, you can perform 
      //any event on that as per your reqirement
      int i_ColNum=1;
      for(WebElement colElement:colCollection)
      {
           System.out.println("Row "+i_RowNum+" Column "+i_ColNum+" Data "+colElement.getText());
           i_ColNum=i_ColNum+1;
       }
    i_RowNum=i_RowNum+1;
 }
 driver.close();
WebDriver=newfirefoxdriver();
driver.manage().window().maximize();
驱动程序。获取(“http://money.rediff.com/");
WebElement=driver.findElement(By.id(“所有页面链接”);
List rowCollection=element.findElements(By.xpath(“/*[@id='allpage_links']]/tbody/tr”);
System.out.println(“此表中的行数:+rowCollection.size());
//在这里,我用i_RowNum和i_ColNum来表示行数和列数。在实时测试用例中可能需要,也可能不需要。
int i_RowNum=1;
for(WebElement行元素:行集合)
{
List colCollection=rowElement.findElements(By.xpath(“td”);
//现在这里有了表的webelements列表,您可以执行
//根据您的要求,在这方面有什么活动吗
int i_ColNum=1;
for(WebElement colElement:colcolcollection)
{
System.out.println(“行”+i_RowNum+“列”+i_ColNum+“数据”+colElement.getText());
i_ColNum=i_ColNum+1;
}
i_RowNum=i_RowNum+1;
}
driver.close();

信息不足。请分享网站的url或HTML代码。谢谢!我使用第二个选项,然后系统选择元素!!!