Selenium Ajax 等待条件

0 投票
1 回答
911 浏览
提问于 2025-04-17 05:41

我正在用Python脚本配合Selenium,想要使用wait_for_condition这个函数。

我想等到这个xpath定义的元素出现:

"/html/body/form/div[3]/div/div/div[2]/div/div/div/table/tbody/tr[8]/td[2]"

所以我尝试了以下代码:

sel.wait_for_condition(
    "var x = selenium.browserbot.findElementOrNull('/html/body/form/div[3]/div/div/div[2]/div/div/div/table/tbody/tr[8]/td[2]'); x != null && x.style.display == 'none';", "5000");

但是它没有效果,有人能告诉我哪里出错了吗?

非常感谢,

祝好

1 个回答

0

超时时间5000应该用整数表示,而不是用字符串。

sel.wait_for_condition(
    "var x = selenium.browserbot.findElementOrNull('/html/body/form/div[3]/div/div/div[2]/div/div/div/table/tbody/tr[8]/td[2]'); x != null && x.style.display == 'none';",
    5000)

文档中也提到:

    Note that, by default, the snippet will be run in the runner's test window, not in the window
    of your application.  To get the window of your application, you can use
    the JavaScript snippet ``selenium.browserbot.getCurrentWindow()``, and then
    run your JavaScript in there.

撰写回答