2016-08-31 2 views
0

すべての国と言語のリストを表示した後、次のページに移動します。以下は私が同じもののために使用しているコードです。私は最初の国のデータを取得し、この後、私は失効例外を取得しています。ループを使用して次のページに移動するときにSelenium Stale例外が発生する

int indexGroupRow = 0; 
    for (WebElement rowElement:listRows) 
    { 
     if (rowElement.getAttribute("class").contains("dxgvGroupRow") 
      && rowElement.getAttribute("id").contains("Content_gvCountries_DXGroupRowExp"+indexGroupRow)) 
     { 
      String t = rowElement.getText(); 
      System.out.println("Country: "+t); 
     } 
     if (rowElement.getAttribute("class").contains("dxgvDataRow") 
      && rowElement.getAttribute("id").contains("Content_gvCountries_DXDataRow"+indexGroupRow)) 
     { 
      String t1 = rowElement.getText(); 
      System.out.println("Available Language: " + t1); 
      List<WebElement> linkElement = rowElement.findElements(By.xpath("td[position()>1]")); 
      for (WebElement er: linkElement) 
      { 
       er.findElement(By.xpath("//*[@id='Content_gvCountries_cell" 
        + indexGroupRow 
        + "_2_lnkSelectCountry_" 
        + indexGroupRow + "']")).click(); 
      } 
     } 
     indexGroupRow++; 
    } 

org.openqa.selenium.StaleElementReferenceException:失効要素 参照:要素がページ文書(セッション 情報:クロム= 52.0.2743.116)に装着されていない(ドライバ情報:chromedriver = 2.16.333243 (0bfa1d3575fc1044244f21ddb82bf870944ef961)、プラットフォーム=のWindows NT 6.1 SP1 x86_64版)(警告:サーバは任意のスタックトレース 情報を提供しなかった)コマンドの期間またはタイムアウト:このエラーの ドキュメントについては26ミリ秒、ご覧ください。 http://seleniumhq.org/exceptions/stale_element_reference.htmlビルドを 情報:バージョン: '2.53.1'、改訂: 'a36b8b1cd5757287168e54b817830adce9b0158d'、時刻: '2016-06-30 19:26:09'システム情報:ホスト: 'WINJITLAPTOP96'、IP: '192.168.224.1'、 os.name: 'Windows 7'、os.arch: 'amd64'、os.version: '6.1'、 java.version: '1.7.0_67'セッションID:adf74ce205fd64d8b3d5c5064781985b ドライバ情報:org.openqa.selenium.chrome .ChromeDriver機能 [{プラットフォーム= XP、acceptSslCerts =真、javascriptEnabled =真、 browserName =クロム、 クロム= {userDataDir = C:\ユーザー\ deepakv \のAppData \ローカル\一時\のscoped_dir11036_1170}、 偽=回転可能で、 locationContextEnabled = true、 mobileEmulationEnabled = false、バージョン= 52.0.2743.116、 takesHeapSnapshot = true、cssSe lectorsEnabled =真、 databaseEnabled =偽、handlesAlerts =真、 browserConnectionEnabled =偽、webStorageEnabled =真、 nativeEvents = TRUE、hasTouchScreen =偽、 applicationCacheEnabled =偽、takesScreenshot} = TRUE] でsun.reflect.NativeConstructorAccessorImpl.newInstance0 (ネイティブメソッド) でsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) java.lang.reflect.Constructor.newInstanceでsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) (ATコンストラクタ.java:526) at org.openqa.selenium.remote.ErrorHandler.createThrowabル(ErrorHandler.java:206) でorg.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)で でorg.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327) でLoginTest.testLoginでorg.openqa.selenium.remote.RemoteWebElement.getText(RemoteWebElement.java:179) (LoginTest。 Javaの:61)アドレス、 ターゲットVMから切断: '127.0.0.1:23563'、輸送: 'ソケット'

答えて

1
for (WebElement er: linkElement) 
     { 
      er.findElement(By.xpath("//*[@id='Content_gvCountries_cell" + indexGroupRow + "_2_lnkSelectCountry_" + indexGroupRow + "']")).click(); 
     } 

最初にクリックすると別のリンクが失われるため、ドライバはlinkElementリストの2番目の要素をクリックできません(前のページに属しているため)。 各クリック後に次のページへのリンクを見つける必要があります

関連する問題