Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 我们可以使用selenium webdriver找到内部HREF值吗?_Ruby_Selenium Webdriver_Xpath - Fatal编程技术网

Ruby 我们可以使用selenium webdriver找到内部HREF值吗?

Ruby 我们可以使用selenium webdriver找到内部HREF值吗?,ruby,selenium-webdriver,xpath,Ruby,Selenium Webdriver,Xpath,请查找以下html代码: <fieldset class="attachmentTable large"><legend>SMF&nbsp;:</legend> <table cellspacing="2" cellpadding="2" border="0"> <tr> <td> <a href=" /aems/file/test.html"> </a> </td> <td

请查找以下html代码:

<fieldset class="attachmentTable large"><legend>SMF&nbsp;:</legend>
<table cellspacing="2" cellpadding="2" border="0">
<tr> <td> <a href="
/aems/file/test.html"> </a> </td>
<td>   foo     </td>
</tr>  </table>
</fieldset>

<fieldset class="attachmentTable large"><legend>tax&nbsp;:</legend>
<table cellspacing="2" cellpadding="2" border="0">
<tr> <td> <a href="

/relf/file/test.html">

</a></td>
<td>  foo   </td>
</tr> </table>
</fieldset>
SMF:
福
税款:
福

使用
XPATH
selenium webdriver
我们可以从html部分获取
/aems/file/test.html

这可能对您有用

link = @driver.find_element(:xpath,"//fieldset[contains(@class,'attachmentTable')]/table/tr/td/a")
href= link.attribute("href")
puts href
更新


我之所以选择
包含
,是因为

这可能适合您

link = @driver.find_element(:xpath,"//fieldset[contains(@class,'attachmentTable')]/table/tr/td/a")
href= link.attribute("href")
puts href
更新


我之所以选择
包含
,是因为

为什么您没有接受
:xpath
元素
图例
?您能解释一下吗?因为这不在路径中,
legend
的标记在相关元素进入图片之前被关闭。为什么这对你不起作用?是的,我只是把它添加到我的代码中,然后运行脚本。实际上,我错误地在我的
:xpath
中添加了
图例,因此失败了。很好,如果这个答案对您有帮助,请将其标记为解决方案。D:\Ruby script>download.rb[远程服务器] file:///C:/Users/ARUPRA~1/AppData/Local/Temp/webdriver-profile20 130124-4648-ag7f6s/extensions/fxdriver@googlecode.com/components/driver\u componen t.js:8251:in`FirefoxDriver.prototype.findElementInternal`中:找不到元素:{“方法”:“xpath”,“选择器”:”//fieldset[@class='attachmentTable large']/table/tr/td/a“}(Selenium::WebDriver::Error::NoTouchElementError)为什么您没有使用
:xpath
元素
图例
?您能解释一下吗?因为这不在路径中,
图例
的标记在相关元素进入图片之前被关闭。为什么这对您不起作用?是的,我只是在代码中添加了它,并运行了脚本。实际上,我错误地添加了
legend
也是在我的
:xpath
中,因此失败了。很好,如果这个答案对您有帮助,请将其标记为解决方案。D:\Ruby script>download.rb[远程服务器] file:///C:/Users/ARUPRA~1/AppData/Local/Temp/webdriver-profile20 130124-4648-ag7f6s/extensions/fxdriver@googlecode.com/components/driver\u componen t.js:8251:in`FirefoxDriver.prototype.findElementInternal`中:找不到元素:{“方法”:“xpath”,“选择器”:”//fieldset[@class='attachmentTable large']/table/tr/td/a“}(Selenium::WebDriver::Error::NoSuchElementError)如何获取
tax,SMF
值?我使用了
driver.find_元素(:xpath,//fieldset[contains(@class,'attachmentTable')]/legend”)
。但没有获取任何值。我犯了什么错误吗?如何获取
tax,SMF
值?我使用了
driver.find_元素(:xpath,//fieldset[contains](@class,'attachmentTable')]/legend”)
。但未获取任何值。是否有错误?