[英]Selenium IDE - TypeError: document.getElementById(..) is null
情况是,我想使用“ runScript”以便在打开网站时开始发送xmlhttprequest,在responseText中找到一个元素,查看是否存在特定的textcontent,如果存在,我要单击该元素。
我不允许向您显示网站的来源,但希望您仍然能够(也许)发现错误。
我的剧本:
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();
}
在将它放入Selenium IDE之前,我已经在firebug控制台中对其进行了测试,并且效果很好。 但是在Selenium IDE中运行它时,总是会遇到相同的异常:
我的问题是:为什么它只能在Firebug中工作,而不能在Selenium IDE中工作,我怎么做错了?
预先感谢您的答复! :)
这表示当您调用document.getElementById()
时,页面尚未完全加载。 您需要将代码包装在window.addEventListener("load", function() { ... });
使它工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.