gpt4 book ai didi

ajax - Selenium 等待条件

转载 作者:行者123 更新时间:2023-12-04 14:47:25 25 4
gpt4 key购买 nike

我是第一次做 Selenium 测试。在主页上,我调用了一些 AJAX,我希望 Selenium 等待元素加载完成。我不确定它是否有效,但我只是输入 selenium 并且 waitForCondition 可以选择。

不管我选择什么,它总是返回“false”。我现在不知道如果 waitForCondition 甚至有效吗?

我如何测试它是否有效?
我在这段代码中做错了什么?

 selenium.waitForCondition("//input[@name='Report'", "3000");
selenium.waitForCondition("//*[@id='MyTable']", "3000");
selenium.waitForCondition("css=.someClass2", "3000");

如果我通过自己的类实现 - 它返回“true”
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

isElementPresent(By.xpath("///*[@id='MyTable']")) - 返回 "true"

最佳答案

waitForCondition仅用于 Javascript 调用,而不用于等待元素加载。

你有什么 isElementPresent很好。我会将它与显式等待结合起来,以便更准确地了解元素何时实际加载并出现在屏幕上:

http://seleniumhq.org/docs/04_webdriver_advanced.html

关于ajax - Selenium 等待条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13588941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com