Ruby on rails 使用Nokogiri打开从XML文件捕获的URL
我使用的是Nokogiri和Cucumber(selenium webdriver),我有一个XML文件: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
<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