此方法將一直等到元素可見。 首先這種方法會檢查,元素是否在HTML可用,無論是顯示..它會等到元素將顯示..
public void E_WaitUntilElementDisplay() throws Exception
{
int i=1;
boolean eleche,eleche1 = false;
while(i<=1)
{
try{
eleche = driver.findElements(by.xpath("path")).size()!=0;
}catch(InvalidSelectorException ISExcep)
{
eleche = false;
}
if(eleche == true)
{
while(i<=1)
{
try{
eleche1=driver.findElement(By.xpath("Path")).isDisplayed();
}catch(org.openqa.selenium.NoSuchElementException NSEE){
eleche1=false;
}
if(eleche1 == true)
{
i=2;
System.out.println("\nElement Displayed.");
}
else
{
i=1;
Thread.sleep(1500);
System.out.println("\nWaiting for element, to display.");
}
}
}
else
{
i=1;
Thread.sleep(1500);
System.out.println("\nWaiting for element, to display.");
}
}
}
這可能是相關:http://stackoverflow.com/questions/15122864/selenium-wait-until-document-is-ready – Minato
可能重複的[在Selenium等待頁面加載](http://stackoverflow.com/questions/5868439/等待頁面裝入硒) –
該元素是在頁面上加載的最後一件事情嗎?有沒有動態的事情發生在網頁上,使得事情在所有事情似乎都被加載後不斷移動?你是否收到關於不存在的元素的錯誤?或元素陳舊? – mrfreester