admin管理员组文章数量:1201982
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="">
Which should change to:
<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").
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
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.
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="">
Which should change to:
<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").
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
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.
4 Answers
Reset to default 7After looking into this I found the answer. I'm documenting it here in case anyone has use for it.
I was running my question code in the FireBug console and it was working correctly; however when executing my script I kept getting SeleniumException
.
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.
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.
Try
document.getElementById('modifyHostsForm:idDnsIp0_0').getAttribute('disabled') == false
You may need to set a variable and then check if it's set or null, so:
var isDisabled = document.getElementById('modifyHostsForm:idDnsIp0_0').getAttribute('disabled')
then the condition becomes:
isDisabled == null || isDisabled == false
Almost... you need:
if(document.getElementById('modifyHostsForm:idDnsIp0_0').disabled == false){
// ^- Capital "B"
//it is not disabled
}
Also make sure you are checking isDisabled == undefined
:
isDisabled == null || isDisabled == false || isDisabled == undefined
本文标签: How to check if an input is disabled with JavaScript in SeleniumStack Overflow
版权声明:本文标题:How to check if an input is disabled with JavaScript in Selenium - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738602303a2102141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
readonly
attribute would also work – Argote Commented Mar 28, 2011 at 22:07disabled == false
?? – amosrivera Commented Mar 28, 2011 at 22:12