我希望驱动程序等到元素可见或存在,但它根本不起作用! 以下代码
it('shows events in "Event overview"', function(){
driver.findElement(By.css('#bs-example-navbar-collapse-1 > ul > li:nth-child(2) > a')).click();
driver.wait(function () {
return driver.isElementPresent(By.css('body > div.container > div > div.events-container.ng-scope > div:nth-child(1) > div.row.row-event.detailed-view > div.col-xs-9.col-sm-9.col-md-10'));
}, 3000);
});
给我以下错误
driver.isElementPresent is not a function
为什么呢?我从这里复制了答案:Selenium WebDriver wait till element is displayed。其他答案也不起作用。我应该展示更多我的代码吗?我在客户端项目上工作,我不想发布客户端的名称。
答案 0 :(得分:6)
I have already answered here for this issue
因此,如果您正在使用Selenium3
并希望等到所需元素存在,则应尝试使用webdriver.until
,如下所示: -
const until = webdriver.until;
var el = driver.wait(until.elementLocated(By.css('body > div.container > div > div.events-container.ng-scope > div:nth-child(1) > div.row.row-event.detailed-view > div.col-xs-9.col-sm-9.col-md-10')), 3000);
答案 1 :(得分:-1)
尝试以下方法:
return driver.findElements(By.css('body > div.container > div > div.events-container.ng-scope > div:nth-child(1) > div.row.row-event.detailed-view > div.col-xs-9.col-sm-9.col-md-10')).size() != 0;