nautical nautical - 8 months ago 80
Javascript Question

Selenium IDE fails getElementById()

I have the following statement in my

Selenium IDE


But this always fails with the error

[info] Executing: |store | javascript{window.document.getElementById('demo').innerHTML} | text |
[error] Unexpected Exception: TypeError: window.document.getElementById(...) is null.

The HTML source code I am using is from w3schools. The corresponding HTML source is

<p id="demo">Click the button to change the text in this paragraph.</p>

<button onclick="myFunction()">Try it</button>

function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";

There is no problem when I execute just


but trying to retrieve an element by its id is not working. What am I missing?


Actually you are using main document while desire I'd element is inside an iframe you need to call getElementById on iframe document as below :-

document.getElementById("iframe Id").contentDocument.getElementById("demo").i‌​nnerHTML = "Hello World";