8

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.

3
  • p.s. checking for the readonly attribute would also work Commented Mar 28, 2011 at 22:07
  • are you using double equals to assign in your code? disabled == false ?? Commented Mar 28, 2011 at 22:12
  • 1
    no, it is not an assignment, it is a check. Commented Mar 28, 2011 at 22:15

4 Answers 4

7

After 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.

Sign up to request clarification or add additional context in comments.

Comments

6

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

2 Comments

The log now shows the following error for the SeleniumException: "'doument.getElementById(...)' is null or not an object"
Simply using getElementById().disabled will always return true or false, there is no null. In cases like mine this is more convenient.
1

Almost... you need:

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

4 Comments

The if is supposed to be handled by selenium, I should just pass the function to evaluate. I had not seen the capital B thing though, I'll see how that works.
Capitalizing the B changed the Exception error to "Object Required".
I'm guessing this is failing because you are trying to get the "disabled" property of a null object reference. are you sure this object with the id: modifyHostsForm:idDnsIp0_0 exists?
Yes, I've isolated the object id using Bugzilla. on the same screen where this script is being executed.
1

Also make sure you are checking isDisabled == undefined:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.