我无法从网络表格中获取文本。请参阅下面的屏幕截图,了解我要查找的文本。如何从下面的屏幕截图中获取文本快速应用程序。
在屏幕截图中,如果我找到了快速应用程序,那么我必须单击该用户的编辑链接。下表的 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);
执行上述代码后,我得到 Null 值。请通过提供代码来帮助我解决这个问题。帮助将不胜感激。
<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);
}
请找到我使用的代码。