朋友们好,我想获取td部分中包含的所有表信息。我试过这个代码:
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox');
$driver = RemoteWebDriver::create($host, $capabilities,1000);
$results = $driver->findElements(WebDriverBy::cssSelector('table #listbody tr'));
for($i=0;$i<count($results);$i++)
{
echo $driver->findElement(WebDriverBy::className('rank'))->getext();
sleep(3);
}
我的结构是这样的:
<table id="listbody">
<tr>
<td class="rank">1</td>
<td class="company"><a href="/companies/icbc/" class="exit_trigger_set">
<img alt="" src="http://i.forbesimg.com/media/lists/companies/icbc_50x50.jpg">
<h3>ICBC</h3></a>
</td>
<td>China</td>
<td class="nowrap">$134.8 B</td>
<td class="nowrap">$37.8 B</td>
<td class="nowrap">$2,813.5 B</td>
<td class="nowrap">$237.3 B</td>
</tr>
</table>
更改
echo $driver->findElement(WebDriverBy::className('rank'))->getext();
至
echo $results[$i]->findElement(WebDriverBy::className('rank'))->getext();