如何在Selenium中检查是否使用JavaScript禁用了输入 [英] How to check if an input is disabled with JavaScript in Selenium

查看:79
本文介绍了如何在Selenium中检查是否使用JavaScript禁用了输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用selenium为webapp构建和自动化测试脚本,我正在尝试使用 waifForCondition API的功能等到JS脚本评估为 true

I'm building and automated test script for a webapp using selenium and I'm trying to use the waifForCondition function of the API where it will wait until a JS script evaluates to true.

我目前在页面上有这个来源:

I currently have this source on the page:

<input id="modifyHostsForm:idDnsIp0_0" type="text" name="modifyHostsForm:idDnsIp0_0" readonly="" disabled="">

哪个应更改为:

<input id="modifyHostsForm:idDnsIp0_0" type="text" name="modifyHostsForm:idDnsIp0_0">

一旦我在另一个字段上放置了某个值并在其上触发模糊事件(因此,这个字段变为启用。)

As soon as I put a certain value on another field and fire the "blur" event on it (and this field thus becomes "enabled").

我正在尝试执行以下JS脚本来测试何时启用此字段(基本上我从谷歌搜索):

And I'm trying to execute the following JS script to test when this field is enabled (basically what I found from "Googling"):

document.getElementbyId('modifyHostsForm:idDnsIp0_0').disabled == false

但是我得到一个 SeleniumException ,表示对象没有支持此属性或方法。我能在这做什么?任何帮助将不胜感激。

However I'm getting a SeleniumException which indicates that "Object doesn't support this property or method". What can I do here? Any help would be appreciated.

推荐答案

在调查之后,我找到了答案。我在这里记录它以防万一有人使用它。

After looking into this I found the answer. I'm documenting it here in case anyone has use for it.

我在FireBug控制台中运行我的问题代码并且它正常工作;但是在执行我的脚本时,我一直得到 SeleniumException

I was running my question code in the FireBug console and it was working correctly; however when executing my script I kept getting SeleniumException.

事实证明你需要使用 selenium.browserbot.getCurrentWindow() 让RC在你正在使用的主窗口上执行JS脚本而不是弹出的控制窗口。

It turns out that you need to use selenium.browserbot.getCurrentWindow() for the RC to execute the JS script on the main window you're using instead of the control window that pops up.

因此,我实际需要的JS代码评估最终成为这样:

As such, the JS code I actually need to evaluate ends up being this:

selenium.browserbot.getCurrentWindow().document.getElementById('modifyHostsForm:idDnsIp0_0').disabled == false

哪种工作正常。感谢其他提示。

Which works just fine. Thanks for the other hints.

这篇关于如何在Selenium中检查是否使用JavaScript禁用了输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆