Selenium - 从网站表中提取数据分配给变量

时间:2014-10-08 18:41:24

标签: vba selenium xpath selenium-webdriver

我试图从网站中提取值和标题(字符串),但无法使用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>&nbsp;</td><td class="formtitlenobg" colspan="6" align='right'>
AREA DIMENSIONS&nbsp; &nbsp; &nbsp; (AREA&nbsp;A) <span class='quote'> &nbsp; Front</span> 25.24</td>
</tr>
<tr align="right">
<td class="tablerowlightgreen" width=10>&nbsp;</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>&nbsp;</td>
<td class="tablerow">&nbsp;</td>
</tr>
<tr align="right" nowrap>
<td>&nbsp;</td>
<td class="table" align="left"><strong>
Property&nbsp;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>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table></td>
</tr></table>

1 个答案:

答案 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]")

请注意第二行中的单引号!