我无法使用带有Java的WebDriver从web表的特定行获取特定文本

我无法使用带有Java的WebDriver从web表的特定行获取特定文本,java,xpath,selenium-webdriver,html-table,Java,Xpath,Selenium Webdriver,Html Table,我无法从web表中获取文本。请参阅下面的屏幕截图,了解我要查找的文本。如何从下面的屏幕截图中获取文本快速应用程序 在屏幕截图中,如果我找到快速应用程序,那么我必须单击该用户的编辑链接。 下表的xpath计数代码: //table[@id='ctl00_MasterPlaceHolder_GvUsers']/tbody/tr 我已尝试使用以下代码捕获文本: text = driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHol

我无法从web表中获取文本。请参阅下面的屏幕截图,了解我要查找的文本。如何从下面的屏幕截图中获取文本快速应用程序

在屏幕截图中,如果我找到快速应用程序,那么我必须单击该用户的编辑链接。 下表的xpath计数代码:

//table[@id='ctl00_MasterPlaceHolder_GvUsers']/tbody/tr
我已尝试使用以下代码捕获文本:

text = driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHolder_GvUsers'] 
/tbody/tr["+k+"]/td[3]")).getText();
System.out.println(text);
执行上述代码后,我得到的值为空。 请通过提供代码来帮助我解决这个问题。我们将不胜感激

<table id="ctl00_MasterPlaceHolder_GvUsers" class="btext" cellspacing="0" cellpadding="2" border="0" style="color:#333333;width:100%;border-collapse:collapse;"> <tbody> <tr align="left" style="color:White;background-color:#507CD1;font-weight:bold;"> <tr class="text" style="color: rgb(28, 28, 28); background-color: rgb(249, 182, 115); font-weight: normal; height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$0')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: White; height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$1')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);"> <tr style="background-color: rgb(239, 243, 251); height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$2')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);">
<tr style="background-color: White; height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$3')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);"> <tr style="background-color: rgb(226, 222, 208); height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$4')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);"
<tr style="background-color: White; height: 10px; text-decoration: none;" onclick="javascript:__doPostBack('ctl00$MasterPlaceHolder$GvUsers','Select$5')" onmouseout="javascript:setMouseOutColor(this);" onmouseover="javascript:setMouseOverColor(this);"> <td>7CUser44</td> <td>Swamy m Kumara</td> <td>Quick App</td> <td>QuickApp User</td> <td>Active</td> <td>halcyon2</td> <td>COTTAGE GROVE </td> <td>WI</td> <td> </tr>




   int xpathcount= driver.findElements(By.xpath((OR.getProperty("xpathcount_Users_ID")))).size();
        System.out.println("Number of rows displayed in Site History table: " +xpathcount);
        int k;
        for (k=1;k<=xpathcount;k++)
        {
            Select table = new Select(driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHolder_GvUsers']/tbody/tr["+k+"]/td[3]")));
            text1 = table.getFirstSelectedOption().getText();
            System.out.println("Selected User Level is: "+text1);
            Thread.sleep(2000);
            text = driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHolder_GvUsers']/tbody/tr["+k+"]/td[3]")).getText();
            System.out.println(text);
        }


没有HTML很难给出一个正确的答案,但是这里有一些可能有用的东西。

public void getEditTable(最终WebDriver驱动程序、最终By表、最终字符串查询){
列表行=table.findElements(按.tagName(“tr”));
for(WebElement行:行){
List cols=line.findElements(按.tagName(“td”));
if(cols.get(2.getText().equals(查询)){
列表操作=cols.get(8).findElement(按.tagName(“a”));
操作。获取(0)。单击();
}
}
}

现在我必须指出,这很可能需要你做大量的工作,但也许你能得到主要的想法。我为我的公司CRUD站点做了一些类似于web表的事情。

这里我可以给出一个使用python webdriver的简单示例。但我不知道如何使用java获取文本。参见下面的示例

word=driver_find_element_by_xpath("xpath value which text you need from web table")
print word.text

答案将显示您在web表中选择的内容。

在这里,我已修改了我的代码,如下所示。感谢所有试图帮助我的成员

int xpathcount=     
driver.findElements(By.xpath((OR.getProperty("xpathcount_Users_ID")))).size();
System.out.println("Number of rows displayed in Site History table: " +xpathcount);
int k;
for (k=2;k<=xpathcount;k++)
{
text = driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHolder_GvUsers']
   /tbody/tr["+k+"]/td[3]")).getText();
System.out.println(text);
}
int xpathcount=
driver.findElements(By.xpath((或.getProperty(“xpathcount\u Users\u ID”))).size();
System.out.println(“站点历史记录表中显示的行数:“+xpathcount”);
int k;

对于(k=2;kAre u能够获取行计数。is//table[@id='ctl00\u MasterPlaceHolder\u GvUsers']/tbody/tr返回正确的计数?谢谢你的回答。是的,我得到的行计数正确。你能对用户级列中的文本进行一个小的交叉检查吗。这是在td下还是在td/span之类的其他标签下。它只在td标签下。是的,我想你不会得到一个好的答案。因为如果你不能弄清楚我的答案可以满足您的情况,您必须首先学习编码。感谢您的回复aimbire,我将检查此代码并让您知道此代码的更新。感谢Senthilkumar提供您的答案,将通过将其转换为Java来尝试您的答案。并让您知道结果。
int xpathcount=     
driver.findElements(By.xpath((OR.getProperty("xpathcount_Users_ID")))).size();
System.out.println("Number of rows displayed in Site History table: " +xpathcount);
int k;
for (k=2;k<=xpathcount;k++)
{
text = driver.findElement(By.xpath("//table[@id='ctl00_MasterPlaceHolder_GvUsers']
   /tbody/tr["+k+"]/td[3]")).getText();
System.out.println(text);
}