簡體   English   中英

Selenium Webdriver:等到頁面上出現文本

[英]Selenium Webdriver: wait until text is present on page

我已經試過了:

driver.wait(function() {
  return driver.isElementPresent(webdriver.findElement(By.xpath("//*[contains(text(),'Vanilla Sky Final Scene')]")))
}, 20000).then(function() {
  console.log('worked')
})

和這個:

driver.wait(function() {
  return driver.isElementPresent(driver.findElement(By.xpath("//*[contains(text(),'Vanilla Sky Final Scene')]")))
}, 20000).then(function() {
  console.log('worked')
})

和這個:

driver.wait(function() {
  return driver.findElement(By.xpath("//*[contains(text(),'Vanilla Sky Final Scene')]")))
}, 20000).then(function() {
  console.log('worked')
})

他們似乎都不起作用。 什么是正確的方法?

正確的函數是isDisplayed() ,以下應該起作用:

driver.wait(function() {
  return driver.findElement(By.xpath("//*[contains(text(),'Vanilla Sky Final Scene')]")).isDisplayed();
}, 20000);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM