Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 on rails 使用Nokogiri打开从XML文件捕获的URL_Ruby On Rails_Selenium_Selenium Webdriver_Cucumber_Nokogiri - Fatal编程技术网

Ruby on rails 使用Nokogiri打开从XML文件捕获的URL

Ruby on rails 使用Nokogiri打开从XML文件捕获的URL,ruby-on-rails,selenium,selenium-webdriver,cucumber,nokogiri,Ruby On Rails,Selenium,Selenium Webdriver,Cucumber,Nokogiri,我使用的是Nokogiri和Cucumber(selenium webdriver),我有一个XML文件: <root> <records> <record> <rowA>www.google.com</rowA> </record> </records> </root> 使用此行@browser.get url[0]。content我试图使用从XML文件捕获的u

我使用的是Nokogiri和Cucumber(selenium webdriver),我有一个XML文件:

<root>
  <records>
    <record>
      <rowA>www.google.com</rowA>
    </record>
  </records>
</root>
使用此行
@browser.get url[0]。content
我试图使用从XML文件捕获的url打开浏览器,但收到错误:

f.QueryInterface is not a function (Selenium::WebDriver::Error::UnknownError)

有什么想法吗?

例外情况是由于您试图导航到的URL(而不是如何检索URL)

通过硬编码URL以检索以下内容,可以复制异常:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get('www.google.com')
#=> f.QueryInterface is not a function (Selenium::WebDriver::Error::UnknownError)
您需要将“http://”添加到URL:

require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get('http://www.google.com')
#=> No exception
换句话说,XML文档应更改为:

<root>
  <records>
    <record>
      <rowA>http://www.google.com</rowA>
    </record>
</root>

http://www.google.com

我会这样写代码:

When /^I open my xml file$/ do
  @xml = Nokogiri::XML(File.read("example.xml"))
end

Then /^I should see the url google$/ do
  @browser.get 'http://' + @xml.at('rowA').content
end
您的xml不正确(缺少)
When /^I open my xml file$/ do
  @xml = Nokogiri::XML(File.read("example.xml"))
end

Then /^I should see the url google$/ do
  @browser.get 'http://' + @xml.at('rowA').content
end