如何处理网站上的弹出窗口

时间:2017-12-26 10:11:00

标签: java selenium testing selenium-webdriver automation

标题:处理弹出框 句柄div的selenium代码在同一个窗口中弹出 //包裹预订;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class Dubai {
    public static void main(String[] args) throws Exception {
    System.setProperty ("webdriver.chrome.driver",
                       "C:\\Users\\miyau\\Desktop\\test\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.thomascook.in/");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//div[text()='Not Now']")).click();
        System.out.println("operation complit");
      }
 }
// snapshot of popup## Heading ## 

enter image description here

1 个答案:

答案 0 :(得分:-1)

您可以尝试以下代码:

public class Dubai {
     public static void main(String[] args) throws InterruptedException {
            try {

                   public static void main(String[] args) throws Exception {
    System.setProperty ("webdriver.chrome.driver",
                       "C:\\Users\\miyau\\Desktop\\test\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();

                  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                  WebDriverWait wait=new WebDriverWait(driver,50 );

                  driver.manage().window().maximize();
                  Thread.sleep(500);

                  driver.get("http://www.thomascook.in/");
                  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

                   driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='__st_preview_frame_bpn']")));
                  System.out.println(driver.findElement(By.xpath("html/body/div[1]/div[2]/div[3]/span")).getText());

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

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
}