这是我目前的设置: Windows 10 使用“Windows安装程序”安装Ruby。 Ruby版本2.4
我有ruby gem selenium-webdriver版本2.52.0(我有旧版本,因为它有正常工作的问题。
我想做什么 我导航到“webpagetest.org”我只是填写一个网址并点击“开始测试”按钮。我可以点击按钮,但我的脚本崩溃了。该脚本工作,意味着在UI上单击按钮然后切换到下一个URL,但Selenium给我错误消息,我无法进行交互,因为脚本错误输出。
注意:我可以在运行Yosemite的2012 Mac上运行我的代码而不会出现任何问题。此问题仅在我的Windows 10上运行时才会发生。我需要从我的Windows机器上运行Ruby selenium webdriver。
以下是我正在做的事情的截图,以及该按钮的名称是正确的:
以下是我收到的错误消息
FirefoxDriver.prototype.findElementInternal_': Unable to locate element: {"method":"class name","selector":"start_test"} (Selenium::WebDriver::Error::NoSuchElementError)
以下是我的Windows计算机上命令提示符下的整个错误消息的屏幕截图:
我尝试了以下内容: 添加等待以查看页面是否只是过早点击。 改变了我定位按钮的方式 尝试“提交”而不是点击按钮
这是我目前的代码:
require 'selenium-webdriver'
require 'nokogiri'
require 'open-uri'
require 'yaml'
require 'gmail'
test_site = 'https://www.webpagetest.org'
test_url = 'https://google.com'
# open a firefox browser and navigate to page testing site
driver = Selenium::WebDriver.for :firefox
driver.navigate.to test_site
# enter a URL and press the start test button
driver.find_element(:id, 'url').send_keys test_url
driver.find_element(:class, 'start_test').click
# store the URL of results page
results_url = driver.current_url
puts results_url
puts "made it here!"
# wait for the results page to load and the load time to show
begin
element = driver.find_element(:id, 'LoadTime')
rescue
retry if element.nil?
end
我将不胜感激任何帮助!我认为这个问题与Windows有关(我对Windows很新)。感谢您抽出宝贵时间阅读我的问题!