The situation is, that I want to use "runScript" in order to send a xmlhttprequest in the beginning when the website gets opened, find an element in the responseText, see if a specific textcontent is present and if so, I want to click on that element.
I am not allowed to show you the source of the website, but I hope your still able to (maybe) find the mistake.
My script:
javascript{
var req = new XMLHttpRequest();
req.addEventListener("load", function(event) {
if(req.status >= 200 && req.status < 300)
{
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(req.responseText, "text/html");
if(document.getElementById("application_widgets__0_selectedUserLanguage_label").childNodes[0].textContent=="English")
{
document.getElementById("application_widgets__0_selectedUserLanguage_label").parentNode.click()
}
}
});
req.open("GET", "..............................");
req.send();
}
I've already tested it in the console of firebug before putting it into the Selenium IDE and it works perfectly. But I always get the same exception when running it in Selenium IDE:
My question is: why does it work in firebug but not in selenium IDE and what did I do wrong?
Thanks for the answers in advance! :)
This indicates that the page is not fully loaded yet when you call document.getElementById()
. You need to wrap your code in a window.addEventListener("load", function() { ... });
to get it to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.