Selenium IDE getElementById() 失败

Selenium IDE fails getElementById()

我的 Selenium IDE 脚本中有以下语句: 我 店铺 javascript{window.document.getElementById('demo').innerHTML} 文本

但这总是失败并出现错误

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

我使用的 HTML 源代码来自 w3schools。对应的HTML来源是

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

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

<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World";
}
</script>

我执行的时候没有问题

<tr>
    <td>store</td>
    <td>javascript{window.document.innerHTML}</td>
    <td>text</td>
</tr>

但尝试通过其 ID 检索元素无效。我错过了什么?

实际上你正在使用 main document 而我想要的元素在 iframe 中你需要在 iframe document 上调用 getElementById 作为下面:-

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