1

我正在使用以下 javascript 在 Selenium 中运行 getEval:

document.getElementById("j_id0:j_id3:mainBlock:j_id40").children[0].children[0].children[0].children[0].children[0].children[0] .children[2].children[0].children[0].children[0] .children[0].children[1];

当我在控制台中运行代码时,它会返回正确的结果。

当我导航到我需要定位的元素所在的页面并单击 Selenium 中的“查找”按钮时,它会找到并突出显示正确的元素。但是,当我实际在 Selenium 中运行该行时 - 即使我导航到正确的页面并只运行该行 - 我收到一条消息说

[error]Threw an exception: document.getElementById(...)is null

我怎样才能使它正常工作?

4

1 回答 1

2

只需在您的实际 JS 语句开始之前包含this.browserbot.getUserWindow()并尝试。

selenium.getEval("this.browserbot.getUserWindow().document.getElementById("j_id0:j_id3:mainBlock:j_id40").children[0].children[0].children[0].children[0].children[0].children[0] .children[2].children[0].children[0].children[0] .children[0].children[1]")
于 2013-03-27T07:42:46.190 回答