2017-12-06 1 views
0

Es ist eine CRM-Anwendung, wo ich zwei Pop-ups, die nach der Benutzeranmeldung angezeigt werden sollen, schließen möchte. Ich habe eine Methode für jedes Pop-up erstellt, wo ich darauf warte, dass der Rahmen erkannt wird und auf das Symbol "Schließen" klicke, um das Popup zu schließen. Unten ist der Code:Selenium Webdriver Timeout Ausnahme: Erwartete Bedingung fehlgeschlagen: Warten auf Frame verfügbar

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("html/body/div[10]"))); 

Die Methode frameToBeAvailableAndSwitchToIt tut, was es sagt:

package base; 

import java.awt.AWTException; 
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.annotations.Test; 

public class TC02_VerificationOfCustomerSearchPage extends 
TC01_LoginToRClaimsCRM{ 

@Test(priority = 0) 
public void PendingEmailPopUPClose() throws InterruptedException, 
AWTException{ 
WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("html/body/div[10]"))); 

//Close Pending Email pop-up. 
driver.findElement(By.xpath("html/body/div[1]/div[2]/div[2]/button")).click();  
driver.switchTo().frame("InlineDialog1_Iframe"); 
} 

@Test(priority = 1) 
public void MSCRMPopUPClose() throws InterruptedException, AWTException { 
WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("html/body/div[10]"))); 

//Close MSCRM pop-up. 
driver.findElement(By.xpath(".//*[@id='buttonClose']/div/img")).click(); 

driver.switchTo().frame("InlineDialog_Iframe"); 
} 

@Test(priority = 2) 
public void HomePageVerification() throws InterruptedException, AWTException 
{ 
driver.switchTo().defaultContent(); 

driver.findElement(By.cssSelector(".homeButtonImage")).click(); 

System.out.println("Home page is displayed."); 

Thread.sleep(100); 

System.out.println("Verification of Customer Search page UI."); 

driver.switchTo().frame("contentIFrame0"); 

//Verification of Customer Search page UI. 

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

//Main Policy Holder tab. 
if(driver.findElement(By.tagName("html")).getText().contains("Main Policy Holder")){ 
    System.out.println("Main Policy Holder tab is displayed."); 
    }else{ 
    System.out.println("Main Policy Holder tab is not displayed."); 
    } 

//SEARCH CRITERIA label. 
if(driver.findElement(By.tagName("html")).getText().contains("SEARCH 
CRITERIA")){ 
    System.out.println("SEARCH CRITERIA label is displayed."); 
    }else{ 
    System.out.println("SEARCH CRITERIA label is not displayed."); 
    } 

Thread.sleep(1000); 

//MPH Name text field. 
if(driver.findElement(By.cssSelector("#txtCustomerName")) != null){ 
    System.out.println("MPH Name text field is displayed."); 
    }else{ 
    System.out.println("MPH Name text field is not displayed."); 
    } 

Thread.sleep(2000); 

//MPH Number text field. 
if(driver.findElement(By.cssSelector("#txtCustomerNumber")) != null){ 
    System.out.println("MPH Number text field is displayed."); 
    }else{ 
    System.out.println("MPH Number text field is not displayed."); 
    } 

Thread.sleep(1000); 

//MPH Policy Number. 
if(driver.findElement(By.cssSelector("#txtPolicyNo")) != null){ 
    System.out.println("MPH Policy Number text field is displayed."); 
    }else{ 
    System.out.println("MPH Policy Number text field is not displayed."); 
    } 

Thread.sleep(1000); 

//SEARCH button. 
if(driver.findElement(By.tagName("html")).getText().contains("SEARCH")) { 
    System.out.println("SEARCH button displayed."); 
    }else{ 
    System.out.println("SEARCH button is not displayed."); 
    } 

Thread.sleep(1000); 

//RESET button. 
if(driver.findElement(By.tagName("html")).getText().contains("RESET")) { 
    System.out.println("RESET button displayed."); 
    }else{ 
    System.out.println("RESET button is not displayed."); 
    } 

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
System.out.println("Verification Successfull - Customer Search page UI."); 
} 
} 
+0

Mögliche doppelte von [Selenium Webdriver Exception: Warten auf Frame verfügbar sein] (https://stackoverflow.com/questions/47716039/selenium-webdriver-exception-waiting-for-frame-to-be-available) –

Antwort

0

unten Zeile Sie Probleme verursacht. Es wartet, bis der Rahmen verfügbar ist, und führt dann die Methode driver.switchTo().frame(); aus.

Sie haben einen xpath für einen Rahmen als html/body/div[10] angegeben, der zu 100% falsch ist. Sie sollten bieten und XPath iframe Tag oder benutzen Sie einfach driver.switchTo().frame("InlineDialog1_Iframe");

Wenn Sie warten müssen, bis Rahmen verfügbar ist, stellen Sie sicher, InlineDialog1_Iframe ist ein id oder Name and provide it to frameToBeAvailableAndSwitchToIt` Methode wie folgt:

WebDriverWait wait = new WebDriverWait(driver, 30); 
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@name='InlineDialog1_Iframe or @id='InlineDialog1_Iframe']"))); 
+0

Jetzt habe ich folgende verwendet , aber immer noch, es verursacht den gleichen Fehler: WebDriverWait wait = new Wir bDriverWait (Fahrer, 30); //wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(("InlineDialog_Iframe "))); wait.until (ExpectedConditions.frameToBeAvailableAndSwitchToIt (By.xpath ("// iframe [@ name = 'InlineDialog_Iframe']"))); // oder //wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@id='InlineDialog_Iframe '] "))); –

+0

@SagarbB Bitte aktualisieren Sie Ihre Frage mit Codeänderungen, sagen Sie uns, welche Codezeile eine Exception auslöst und sagen Sie uns, welche Art von Exception ausgelöst wird. –

+0

Unterhalb Linie ist eine Ausnahme- org.openqa.selenium.TimeoutException werfen: Erwarteter Zustand fehlgeschlagen: wartet Rahmen verfügbar sein: By.xpath: // iframe [@ id = 'InlineDialog_Iframe'] \t WebDriverWait warten = new WebDriverWait (driver, 30); \t wait.until (ExpectedConditions.frameToBeAvailableAndSwitchToIt (Von.xpath ("// iframe [@ name = 'InlineDialog1_Iframe']"))); –

Verwandte Themen