加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何使用watir在弹出窗口中输入密码?

发布时间:2020-12-17 02:37:04 所属栏目:百科 来源:网络整理
导读:我正在写一些watir测试用例: browser.goto "http://egauge2592.egaug.es/"browser.link(:href,"/settings.html").clickbrowser.text_field(:index,4).set("some text")browser.button(:id,"save_button").click 然后打开“需要验证”对话框,询问用户名和密
我正在写一些watir测试用例:

browser.goto "http://egauge2592.egaug.es/"
browser.link(:href,"/settings.html").click
browser.text_field(:index,4).set("some text")
browser.button(:id,"save_button").click

然后打开“需要验证”对话框,询问用户名和密码.

无论我怎么试,我都无法访问文本字段.

我尝试了send_keys和JavaScript.

我也试过Watir.autoit,但它说未定义的方法.

我在使用FireFox浏览器的Ubuntu机器上使用watir.

如何填写该对话框的用户名和密码字段?
我能够使用browser.alert.set输入用户名,但只能设置用户名无法访问密码字段.

解决方法

我最近编写了一个firefox插件来处理这个问题.我没有尝试过无头的Firefox,但它可能有用…值得一试.有关详细信息,请参阅以下

http://www.natontesting.com/2012/10/06/firefox-plugin-test-automation-password-manager/

要使其与watir一起使用,请尝试以下操作:

browser = Watir::Browser.new
#go to a page that won't bring up the authentication dialog...
browser.goto 'http://www.google.co.uk'

#prepare the script...
pass_man_update_script = <<-SCRIPT
var addCredentialsEvent = new CustomEvent("add_credentials_to_passman",{
  detail: {
    host: 'http://secure.example.com',username: 'bob',password: 'P45sword'
  }
});
window.dispatchEvent(addCredentialsEvent);
SCRIPT

#inject the script into the browser:
browser.execute_script pass_man_update_script

#go to the page that prompts the dialog box...
browser.goto "http://secure.example.com"
#you should now be past the dialog box!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读