我在用:
driver.manage().timeouts().implicitlyWait(180, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
但是对于下面的元素,它仍然会不断失败
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("Create_title_01");
Run Code Online (Sandbox Code Playgroud)
我添加了等待代码:
for (int second = 0;; second++) {
if (second >= 120) fail("timeout");
try { if (isElementPresent(By.id("name"))) break; } catch (Exception e) {}
Thread.sleep(1000);
}
Run Code Online (Sandbox Code Playgroud)
不应该隐含等待,直到找到一个元素?如果我使用显式等待而不是我添加的代码,它会更好Thread.sleep()吗?
我的两个场景 -
1)首先
@driver.manage.timeouts.implicit_wait = 30
@wait = Selenium::WebDriver::Wait.new(:timeout => 45) # Time greater than implicit
@wait.until {@driver.find_element(:tag_name => "body").text.include?("hey")}
Run Code Online (Sandbox Code Playgroud)
这给了驱动程序45秒搜索文本(这是预期的)
2)第二
@driver.manage.timeouts.implicit_wait = 30
@wait = Selenium::WebDriver::Wait.new(:timeout => 5) # Time less than implicit
@wait.until {@driver.find_element(:tag_name => "body").text.include?("hey")}
Run Code Online (Sandbox Code Playgroud)
这现在为驱动程序提供了30秒的搜索时间(不是预期的)
有没有办法让硒等待explicit等待时间而不是两者中的较大者?
注意 - 不是声明隐式等待时间不是一个选项,因为每次驱动程序无法找到某些内容时我都无法让selenium挂起.
使用Selenium版本30,windows,ff
当隐式等待小于显式时会发生误解:
var timeOut = 5000;
var search = element(by.xpath(`//*[@name='qwer']`));
browser.manage().timeouts().implicitlyWait(4000);
browser.ignoreSynchronization = true;
describe('Protractor Test', function () {
beforeEach(function () {
browser.get('https://www.google.com.ua');
});
it('EC', function () {
console.log('START');
// browser.sleep(timeOut);
browser.wait(protractor.ExpectedConditions.presenceOf(search), timeOut);
});
});
Run Code Online (Sandbox Code Playgroud)
总时间:8.613秒.隐式设置等待第二个低位:3000,结果为6.865秒.它是如何在引擎盖下工作的?非常感谢提前!
我遇到了一种情况,我需要等待一个元素消失(在 Firefox 中)。所以我尝试了不同的选项,但没有任何效果,所以尝试使用
new WebDriverWait(Drivers._driverInstance, new TimeSpan(0, 0, 2)).Until(ExpectedConditions.InvisibilityOfElementLocated(locator));
Run Code Online (Sandbox Code Playgroud)
这可行,但运行测试用例需要 26 秒。我评论这句话的时候花了一半的时间。为什么这种特殊方法需要更多时间。虽然我只提到了 2 秒,但实际上已经等待了近 10 秒。为什么会这样呢?有没有更快的方法来等待元素消失。
谢谢。