【问题标题】:How to input text into textfield with Selenium and Nokogiri?如何使用 Selenium 和 Nokogiri 在文本字段中输入文本?
【发布时间】:2016-06-10 09:24:15
【问题描述】:

我正在使用 Selenium Webdriver、Chromedriver 和 Nokogiri。我编写了一个脚本来访问 Google.com 并解析页面:

require "selenium-webdriver"
require "nokogiri"
browser = Selenium::WebDriver.for :chrome
browser.get "https://google.com"
doc = Nokogiri::HTML.parse(browser.page_source)

现在,如何使用我的 ruby​​ 脚本在搜索栏中输入文本?搜索栏的 ID 为 #lst-ib

【问题讨论】:

  • Selenium 已经提供了很多方法来定位页面的 HTML 部分。通过使用 Nokogiri,您可以定位相同的元素,但无法与找到的元素交互

标签: ruby xml selenium automation nokogiri


【解决方案1】:

根据Link 此处提供的信息,您可以执行以下操作:

input = wait.until {
    element = browser.find_element(:id, "lst-ib")
    element if element.displayed?
}
input.send_keys("Input") 

【讨论】:

    猜你喜欢
    • 2013-10-08
    • 2021-02-26
    • 1970-01-01
    • 2012-06-30
    • 2016-03-27
    • 2015-06-11
    • 2021-12-30
    相关资源
    最近更新 更多