다음은 내 코드입니다. 아래 코드는 경고 상자를 제거 할 수 있지만 콘솔에서는 오류가 발생합니다.
스레드 "main"의 예외 org.openqa.selenium.UnhandledAlertException : 모달 대화 상자 있음 :이 페이지에서 나가면 모든 변경 사항이 손실됩니다. 빌드 정보 : 버전 : '3.0.1', 수정 : '1969d75', 시간 : '2016-10-18 09:48:19 -0700' "인테넷 익스플로러 11을 사용하고 있습니다.
driver.findElement(By.xpath("//div[@id=ctl02_cp1_ucGI")).click();
Thread.sleep(4000);
if (ExpectedConditions.alertIsPresent() != null)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.onbeforeunload = function() {};");
System.out.println("alert is present");
}
else
{
System.out.println("alert is not present");
}
Thread.sleep(4000);
WebElement product1=driver.findElement(By.xpath("//select[@id='ctl00_cp1_ucGI_ddlProduct']"));
셀레늄을 통해 경고를 수락 할 수 있습니다.
public void checkAlert()
{
try
{
// Wait for the alert is present
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
// Switch to the alert
Alert alert = driver.switchTo().alert();
// Close the alert
alert.accept();
}
catch (Exception e)
{
//exception handling
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다