Selenium Webdriver超时异常:预期条件失败:等待帧可用

时间:2017-12-06 12:14:33

标签: java selenium-webdriver

这是一个CRM应用程序,我想关闭两个弹出窗口,一旦用户登录就会显示。我为每个弹出窗口创建了一个方法,我正在等待它的框架检测并点击“关闭”#39;图标关闭弹出窗口。以下是代码:

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

1 个答案:

答案 0 :(得分:0)

以下行导致您遇到麻烦:

$ npm install --save typescript @types/node @types/react @types/react-dom @types/jest

方法WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("html/body/div[10]"))); 完成它所说的。它等待框架可用,然后执行frameToBeAvailableAndSwitchToIt方法。

您为driver.switchTo().frame();提供了一个xpath,这是100%不正确的。 您应该为html/body/div[10]标记提供和xpath,或者只使用iframe

如果您需要等到框架可用,请确保driver.switchTo().frame("InlineDialog1_Iframe");InlineDialog1_Iframe或名称id frameToBeAvailableAndSwitchToIt`方法,如下所示:

and provide it to