我试图从网站中提取值和标题(字符串),但无法使用selenium找到该元素。
我的代码
我使用Firebug来获取XPath,这就是它所确定的:
//*[@id="DimensionForm"]/p[1]/table/tbody/tr[3]/td[3]
代码
Dim Right as double
Dim Marker as string
Marker = selenium.findElementByXPath("//*[@id="DimensionForm"]/p[1]/table/tbody/tr[2]/td[3]").getAttribute("value")
Right = selenium.findElementByXPath("//*[@id="DimensionForm"]/p[1]/table/tbody/tr[3]/td[3]").getAttribute("value")
HTML CODE
<form id="DimensionForm" name="validate" action="Dimension" method="post">
<div style="margin-top: 7px"></div>
<p><table width="100%" cellspacing="0" border="0" cellpadding="0" class="element">
<tr>
<td> </td><td class="formtitlenobg" colspan="6" align='right'>
AREA DIMENSIONS (AREA A) <span class='quote'> Front</span> 25.24</td>
</tr>
<tr align="right">
<td class="tablerowlightgreen" width=10> </td>
<th class="formtitle" width=250 align="left">Property</th>
<th class="formtitle" width=50>Check</th> <th class="formtitle" width=75>Front</th>
<th class="formtitle" width=75>Center</th><th class="formtitle" width=75>Left</th>
<th class="formtitle" width=120>Right</th>
<th class="formtitle" width=100>Total</th>
<td class="tablerow" width=50> </td>
<td class="tablerow"> </td>
</tr>
<tr align="right" nowrap>
<td> </td>
<td class="table" align="left"><strong>
Property O</strong></td>
<td class="table">+</td>
<td class="table">10</td>
<td class="table">12</td>
<td class="table"><strong>12</strong></td>
<td class="table"><strong><font class="front">
100</font></strong></td>
<td class="table">120</td>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr></table>
答案 0 :(得分:1)
您错误地嵌套了引号:
selenium.findElementByXPath("//*[@id="DimensionForm"]/p[1]/table/tbody/tr[2]/td[3]")
也许你的意思是:
selenium.findElementByXPath("//*[@id='DimensionForm']/p[1]/table//tr[2]/td[3]")
请注意第二行中的单引号!