Tag: 机器人

在从Beginning Ruby书的第12章中尝试一些代码时,如何摆脱这个RunTimeError?

对不起,如果这是一个总的新手问题,但我不知道如何解决这个问题。 我在尝试运行以下代码时遇到这些错误: bot.rb:58:in `rescue in initialize’: Can’t load bot data (RunTimeError) bot.rb:55:in `initialize’ basic_client.rb:3:in `new’ basic_client.rb:3:in `’ 这是bot.rb的源代码,错误似乎出现在“@data = YAML.load(File.open(options [:data_file])。read)”部分。 # A basic implementation of a chatterbot class Bot attr_reader :name # Initializes the bot object, loads in the external YAML data # file and sets the bot’s name. Raises an exception if # […]

如何在执行操作之前让Selenium / Ruby bot等待?

我正在构建一个点击元素的Selenium / Ruby Web机器人。 问题是,在僵尸程序决定无法找到该元素之前,有时没有足够的时间加载页面。 在执行操作之前让Selenium等待的Ruby方法是什么? 我更喜欢明确的等待,但我也很好地隐瞒等待。 我试着使用wait.until方法: require “selenium-webdriver” require “nokogiri” driver = Selenium::WebDriver.for :chrome wait = Selenium::WebDriver::Wait.new(:timeout => 15) driver.navigate.to “http://google.com” driver.wait.until.find_element(:class, “gb_P”).click 但是我收到以下错误: Undefined method ‘wait’ for 我也尝试过: require “watir-webdriver/wait” … driver.find_element(:class, “gb_P”).wait_until.click 但这也给了我一个未定义的方法错误: undefined method `when_present’ for #