2017-06-30 5 views
0

このページに表示されているトランザクション番号と、次のページに表示されているトランザクション番号とを比較しようとしています。 。前のページの値とwebdriverの新しく開いたページの値を比較する方法

enter image description here

私は次のことを試してみました:

// -----------------------Selecting values in the form------------------- 
// Call the function to select a date from calendar e.g. 2016/04/19   
     ClaimsOnline_fields.pickExpDate("19",4,2016); 

// In the Transaction Types dropdown, select a value e.g. "Realtime Transactions Only" 
     TransTypesDrop = new Select(drivers.findElement(By.xpath(".//*[@id='type']"))); 
     TransTypesDrop.selectByVisibleText("Realtime Transactions Only");  

// In the Dataset dropdown, select a value e.g. "5 - DJCJ0005" 
     DatasetDrop = new Select(Utilities.drivers.findElement(By.xpath(".//*[@id='logbook_form']/table/tbody/tr[1]/td/fieldset/table/tbody/tr[7]/td[2]/select"))); 
     DatasetDrop.selectByVisibleText("5 - DJCJ0005");   

// Click the Show button   
     drivers.findElement(By.xpath(".//*[@id='logbook_form']/table/tbody/tr[2]/td/input[1]")).click(); 

     Utilities.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/table[2]"))); 

     batchVal = drivers.findElements(By.className("results")); 

//----------------------- Drill into test result --------------------------       

List<String> all_elements_text=new ArrayList<>(); 
//  Click the first result 
     for(int i=0; i<batchVal.size(); i++){ 

//   Click the Transaction No of the first result 
      batchVal.get(1).click();    

//   The next page is opened 
      Utilities.wait.until(ExpectedConditions.presenceOfElementLocated(By.className("jqi"))); 
      Utilities.wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("jqi"))); 

      drivers.findElement(By.className("jqidefaultbutton")).click(); 

      Utilities.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/p"))); 

      String TransNo = drivers.findElement(By.xpath("html/body/p")).getText(); 

      Utilities.wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/p"))); 

//   Add the value from the search result into the array 
      all_elements_text.add(batchVal.get(i).getText()); 

//   get the currently displayed Transaction Num 
      String TransNoTrimmed = TransNo.substring(34,48); 

//    
      if(all_elements_text.get(1).equals(TransNoTrimmed)){ 
       System.out.println("Test Passed - Claims Online - Logbook - Drill into Results - Transaction Number matches one displayed in the drilled results i.e. "+TransNoTrimmed); 
      } 
      break; 
     } 

私はこれを実行すると、私は次のエラーを取得する:

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document (Session info: chrome=59.0.3071.115) (Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information)

答えて

1

次の行を置き換えます。

drivers.findElements(By.className("results")).get(i).click();

batchVal.get(1).click();

ここで何が起こっているかStaleElementReferenceException

を避けるために、あなたはWebElementsのオブジェクトを作成し、その後、あなたはその上でクリックしているように、ありますページ。クリック後にページの一部が変更され、保存された要素が古くなってしまい、Webdriverが教えてくれるものです。

+0

にセレンのための新しいChrome拡張機能ファイルをダウンロードし、セレンを使用します(all_elements_text.get場合 (1).equals(TransNoTrimmed)){ System.out.println( "テスト合格 - クレームオンライン - ログブック - 結果へのドリル - トランザクション番号はドリル結果に表示されるもの、" + TransNoTrimmed)。 } – Mlungisi

+0

私はあなたにコードを置き換えると言っている正確な場所。リストに要素を格納してから使用すると、ページ上でマイナーなものが変更された場合でも 'StaleElementReferenceException'がスローされます。 –

0

ちょうど私は、前のページからのデータを比較するとき、私はで掘削した後、問題が新しいページのデータに発生した3

関連する問題