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.
isEnabled() This method verifies if an element is enabled. If the element is enabled, it returns a true value. If not, it returns a false value.
Use the disabled property to check if an element is disabled, e.g. if (element. disabled) {} . The disabled property returns true when the element is disabled, otherwise false is returned.
Steps to follow: Go to “https://www.studysection.com/users/login”. Go to the “Log in” field, right-click on it and then click on inspect element. We can see the id for the login field is “UserEmail”.
isEnabled() This will generally return true for everything but disabled input elements. Returns: True if the element is enabled, false otherwise.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With