我是新手。我正在尝试使用selenium
抓取一个网站。这是网站https://www.ventusky.com/。网站上的每个点都提供有关鼠标悬停和点击的信息。我正在尝试执行点击网站的简单任务。这是我的代码。
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.navigate.to "http://ventusky.com/"
wait = Selenium::WebDriver::Wait.new(:timeout => 50) # seconds
test = driver.find_element(:id,"l")
driver.action.click(test).perform
driver.quit
但是这会引发从perform
代码行发生的错误。
/home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/w3c_bridge.rb:626:in `raw_execute': unknown command: :mouse_move_to (ArgumentError)
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/w3c_bridge.rb:615:in `execute'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/remote/w3c_bridge.rb:418:in `mouse_move_to'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/mouse.rb:69:in `move_to'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/mouse.rb:79:in `move_if_needed'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/mouse.rb:33:in `click'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/action_builder.rb:354:in `block in perform'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/action_builder.rb:353:in `each'
from /home/raj/.rvm/gems/ruby-2.3.1/gems/selenium-webdriver-3.0.5/lib/selenium/webdriver/common/action_builder.rb:353:in `perform'
from windy.rb:9:in `<main>'
我不明白这里发生了什么。我认为这是ActionBuilder
的问题。我错过了什么?
答案 0 :(得分:1)
您可以直接在找到的节点上调用click
方法:
driver.find_element(:id,"l").click