2017-02-14 19 views
2

Javaでセレンを使用しています。そのページで何らかのアクションを実行する前に、ページが完全にロードされるのを待っています。ページがSeleniumに完全に読み込まれるまで待ちます

次の方法を試しましたが、期待どおりに動作しません。

public void waitForElementToBeVisible(final WebElement element) { 

    WebDriverWait wait = new WebDriverWait(WebDriverFactory.getWebDriver(), WEBDRIVER_PAUSE_TIME); 

    wait.until(ExpectedConditions.visibilityOf(element)); 
+0

これはあるかもしれません関連:http://stackoverflow.com/questions/15122864/selenium-wait-until-document-is-ready – Minato

+0

「[Seleniumでページの読み込みを待つ]」の重複が考えられます(http://stackoverflow.com/questions/5868439/ページング待ちセレン待ち) –

+0

その要素はページに最後にロードされますか?ページに何か起こっている動的なものがあるので、すべてがロードされたように見えても動き続けるのですか?存在しない要素に関するエラーが発生していますか?または要素が古くなっていますか? – mrfreester

答えて

2

WebDriverWaituntilを待つようなメソッドを継承します。..要素が表示されますまで、それは待機します。..要素はHTMLで、それは表示のかどうか利用可能かどうか、チェックします。

ので

webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(elementLocator)

ようなものが動作するはずです。 ExpectedConditionsを使用すると、作業が簡単になります。

if(element.isDisplayed() && element.isEnabled()){ 
    //your code here 
} 

またはあなたが待ちたいどのくらい知っている場合:あなたはまた、この方法visibilityOfAllElements

0

このメソッドは、要素が表示されるまで待機します。 まず、この方法では

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."); 
      } 
    } 
} 
+0

ホープ..私の答えはあなたを助けます..または答えに近づくでしょう.. Eddie、インドからの感謝。 –

0


は、多分あなたはのような何かを試すことができます別の選択肢として使用することができます

thread.sleep(3000); //where 3000 is time expression in milliseconds, in this case 3 secs 
関連する問題