【问题标题】:how to handle popups on website如何处理网站上的弹出窗口
【发布时间】:2018-06-07 04:49:51
【问题描述】:

title : 处理弹出框 在同一窗口上处理 div pop 的 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 ## 

【问题讨论】:

    标签: java selenium testing selenium-webdriver automation


    【解决方案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();
                }
    
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      • 2018-03-22
      相关资源
      最近更新 更多