在警报Selenium Webdriver上单击“确定"

编程入门 行业动态 更新时间:2024-10-26 04:27:58
本文介绍了在警报Selenium Webdriver上单击“确定"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

好吧,所以我知道关于webdriver中警报的问题还有很多其他答案,我已经仔细研究了它们,但我认为我的情况有所不同.当我单击提交按钮时,我已经切换到3帧,然后收到警报,因此我尝试切换回默认内容,然后使用try catch和alert.accept单击警报,但仍然没有单击警报.代码如下.预先感谢您的协助:)

Ok so I know there are a number of other answers on this question about alerts in webdriver and I've looked through them but I think my situation is a little different. When I click my submit button I have already switched into 3 frames and then I get the alert, so I tried to switch back to default content and then click the alert using a try catch and alert.accept but it still doesn't click the alert. Code is below. Thanks in advance for your assistance :)

public class BookAHoliday { public FirstPage completeHolidayFormAndSubmit(String firstDate, String lastDate) { sleepsAreBad(); driver.switchTo().frame("ContainerFrame"); driver.switchTo().frame("iframeCommunityContainer"); driver.switchTo().frame("FORMCONTAINER"); fluentWait(By.id("StartDate_txtInput")); firstDayOfLeaveInput.sendKeys(firstDate); sleepsAreBad(); lastDayofLeaveInput.sendKeys(lastDate); try { submitButton.click(); } catch (UnhandledAlertException f) { try { sleepsAreBad(); driver.switchTo().defaultContent(); Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); System.out.println("Alert data: " + alertText); alert.accept(); } catch (NoAlertPresentException e) { e.printStackTrace(); } } sleepsAreBad(); return PageFactory.initElements(driver, FirstPage.class); } private void sleepsAreBad() { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } public class BaseTest { public static WebDriver driver; static String driverPath = "C:\\"; @BeforeClass public static void setUp() { System.out.println("****************"); System.out.println("launching Browser"); System.out.println("****************"); // Browser selection //Firefox DesiredCapabilities dc = new DesiredCapabilities(); dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE); driver = new FirefoxDriver(dc); driver.get(URL); @AfterClass() public static void tearDown() { if (driver != null) { System.out.println("Closing browser"); driver.quit(); } } public class Bookings extends BaseTest{ @Test(description = "Holiday booking") public void CD01() { FirstPage firstPage = PageFactory.initElements(driver, FirstPage.class); firstPage .logIn("username", "password") .clickHolidayLink() pleteHolidayFormAndSubmit("12/05/2016", "15/05/2016"); }

警报框这是警报框

推荐答案

在catch

WebDriverWait wait = new WebDriverWait(driver, 3000); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = webDriver.switchTo().alert(); alert.accept();

也许会帮助您...:)

May be it will help you...:)

更多推荐

在警报Selenium Webdriver上单击“确定"

本文发布于:2023-11-27 15:49:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638632.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   单击   Webdriver   Selenium   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!