How to check if JavaScript login is disabled in Selenium

I am creating an automated test script for webapp using selenium, and I am trying to use the waifForCondition API function where it will wait until the JS script is true .

I currently have this source on the page:

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

What should change to:

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

As soon as I put a certain value in another field and started the β€œblur” event on it (and this field becomes β€œon”).

And I'm trying to run the following JS script to check when this field is turned on (basically what I found from "Google"):

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

However, I get a SeleniumException that indicates that "Object does not support this property or method." What can i do here? Any help would be appreciated.

+7
source share
4 answers

Looking at this, I found the answer. I am documenting it here if someone is using it.

I ran my question code in the FireBug console and it worked correctly; however, while running my script, I kept getting a SeleniumException .

Turns out you need to use selenium.browserbot.getCurrentWindow() for RC to execute the JS script in the main window, which you use instead of the control window that appears.

So the JS code that I really need to evaluate ends with the following:

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

Which works just fine. Thanks for the other tips.

+7
source

Try

 document.getElementById('modifyHostsForm:idDnsIp0_0').getAttribute('disabled') == false 

You may need to set the variable and then check if it is set or null, like so:

 var isDisabled = document.getElementById('modifyHostsForm:idDnsIp0_0').getAttribute('disabled') 

then the condition will be:

 isDisabled == null || isDisabled == false 
+5
source

Almost ... you need:

 if(document.getElementById('modifyHostsForm:idDnsIp0_0').disabled == false){ // ^- Capital "B" //it is not disabled } 
+1
source

Also make sure you check isDisabled == undefined :

isDisabled == null || isDisabled == false || isDisabled == undefined

+1
source

All Articles