Selenium Webdriver - 如何关闭第一个弹出窗口并转到实际页面 [英] Selenium Webdriver - how to close the first pop up window and go to the actual page

查看:24
本文介绍了Selenium Webdriver - 如何关闭第一个弹出窗口并转到实际页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动化网页http://www.quikr.com",当我打开这个你会看到一个弹出窗口,首先说请选择你的位置",然后关闭它后,我可以看到 quikr 的主页.

I'm trying to automate the webpage "http://www.quikr.com",when I open this you will get a pop up window first saying "Please Choose Your Location" then after closing it , I can see the main page of quikr.

我尝试通过自动关闭该弹出页面,但无法做到

I tried closing that Popup page by automation ,but not able to do

尝试使用 xpath

 driver.findElement(By.xpath("//*[@id='csclose']/strong")).click();

尝试使用 className

Tried using className

 driver.findElement(By.className("cs-close cs-close-v2")).click();

尝试使用 id

  driver.findElement(By.id("csclose")).click();

请帮我解决这个问题

推荐答案

以下代码适用于我在 Selenium Webdriver 中处理弹出窗口/警报只需在触发弹出窗口/警报的事件之后复制粘贴此代码,即在单击保存之后.

The Following Code Works for Me to Handle Pop Up/ Alerts in Selenium Webdriver Just Copy Paste this Code After the Event which is triggering the Pop up/Alert i.e after clicking on save.

if(driver.switchTo().alert() != null)
{
    Alert alert = driver.switchTo().alert();
    String alertText = alert.getText();
    alert.dismiss(); // alert.accept();

}

在您的情况下,您尝试在代码开始时运行此代码 bcz 它将直接关闭弹出窗口

in your case you try to run this code at starting of the code bcz it will directly close the pop up

这篇关于Selenium Webdriver - 如何关闭第一个弹出窗口并转到实际页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆