【问题标题】:Inserting text into the text field is not happening in IE 11在 IE 11 中没有将文本插入文本字段
【发布时间】:2017-01-10 04:47:00
【问题描述】:

我正在尝试将文本输入到“www.google.com”的文本框中,虽然它说存在文本字段,但它没有将数据输入到文本字段中。同样适用于 FF 46.0 和 chrome。

下面是我的代码

require 'rubygems'
require 'watir'

browser = Watir::Browser.new(:ie)
browser.goto('www.google.com')

browser.wait_until(60) {
    browser.div(:id, 'sb_ifc0').present?
}
if browser.div(:id, 'sb_ifc0').present?
    p 'search bar'
end

if browser.input(:class, 'gsfi').present?
    p 'input present'
    browser.text_field(:class, 'gsfi').set('watir')
    p browser.text_field(:class, 'gsfi').value        
    browser.send_keys :enter
end

ie浏览器的输出如下

"search bar"
"input present"
""

另外请注意,我在后台运行 selenium 集线器和节点。 hub和node在前台运行时没有问题

我正在使用以下设置 selenium 独立服务器 2.53.1、watir gem 版本 5.0.0、selenium-webdriver gem 版本 2.53.1、IE 版本 11、IEDriverServer_Win32_2.53.1。

【问题讨论】:

    标签: ruby internet-explorer selenium internet-explorer-11 watir


    【解决方案1】:

    http://www.google.com 输入框为<input name="q" ... >,没有class,所以watir 找不到。

    将您的 text_field 查找改为使用 name

    require 'rubygems'
    require 'watir'
    
    browser = Watir::Browser.new 
    browser.goto('www.google.com')
    
    browser.text_field(:name => 'q').set('watir')
    browser.button(:type => 'submit').click
    
    p browser.url
    

    我还必须更改 send_keys :enter 部分,因为这对我不起作用,而且我找不到使用回车按钮的解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-13
      • 2020-05-20
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多