2015-12-21 29 views
0

上我已經試過這樣:硒的webdriver:等到文本存在

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') 
}) 

他們似乎都不上班。什麼是正確的做法?

回答

2

正確的功能是isDisplayed(),下面應該工作:

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

我想你的意思'isDisplayed()' - 我會編輯,但是我只需要編輯一個字符,SO最小編輯是6個字符:) – JoeyC

+0

感謝糾正它。 –