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