driver.wait(until.elementIsPresent(By.css(".popup-backdrop fade")), 15000);
我该怎么做呢?我想等到“.popup-backdrop fade”叠加层消失后再单击一个元素。
我正在使用Selenium-webdriver(使用Javascript而不使用Java或Python或C#)
答案 0 :(得分:3)
在代码源中没有找到否定等待。解决方案是实现自己的条件:
var webdriver = require('selenium-webdriver');
var until = webdriver.until;
var By = webdriver.By;
until.elementIsNotPresent = function elementIsNotPresent(locator) {
return new until.Condition('for no element to be located ' + locator, function(driver) {
return driver.findElements(locator).then(function(elements) {
return elements.length == 0;
});
});
};
driver.wait(until.elementIsNotPresent(By.css(".popup-backdrop fade")), 15000);
答案 1 :(得分:1)
这是问题的另一种解决方案,更内联(但它有效,而不是与“TypeError:until.Condition不是构造函数”崩溃的已接受答案):
await this._webDriver.wait(() => {
return this._webDriver.findElements(By.id('loadingIndicator')).then(function(found) {
return found.length === 0;
});
}, 3000, 'The element should disappear');
答案 2 :(得分:0)
您也可以尝试以下方式:
let faderElement = webdriver.By.css('.fader');
driver.wait(webdriver.until.elementLocated(faderElement));
let faderElementFound = driver.findElement(faderElement);
driver.wait(webdriver.until.elementIsVisible(faderElementFound));
driver.wait(webdriver.until.elementIsNotVisible(faderElementFound));
答案 3 :(得分:0)
如已接受问题的注释所示,直到.Condition在Selenium 4中不是有效的构造函数。相反,可以执行以下操作:
const { By, until, Condition } = require('selenium-webdriver');
until.elementIsNotPresent = function elementIsNotPresent(locator) {
return new Condition('for no element to be located ' + locator, function(driver) {
return driver.findElements(locator).then(function(elements) {
return elements.length === 0;
});
});
};
使用Condition的参考可以在这里找到: https://github.com/seleniumhq/selenium/issues/2755