关于如何在同一网页上处理框架和多个弹出窗口的Selenium代码?

时间:2017-02-13 09:42:12

标签: javascript java selenium selenium-webdriver

我正在研究java Selenium WebDriver。我想在同一个网页上处理框架和多个弹出窗口?

我已完成处理框架并返回默认内容。现在我在同一网页上处理多个弹出窗口时遇到问题?

我尝试过以下方法:

//First method

WebDriverWait wait =   new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.id("masterPOP")));
driver.findElement(By.id("close-popup")).click();

//Another method

Alert alert = driver.switchTo().alert();
alert.dismiss();

//I am sharing my code below:

package BRA_product;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class frameeeeeee {

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

        String exePathGecko=("C:\\Users\\Prerna\\Downloads\\geckodriver.exe");
        System.setProperty("webdriver.gecko.driver",exePathGecko);

      WebDriver driver=new FirefoxDriver();
       //Zivame home page
     driver.get("http://www.zivame.com/#?");

     //switch to frame
       driver.switchTo().frame("webpush-bubble"); 
       driver.findElement(By.xpath(".//*[@id='deny']")).click();
       //back to home page
       driver.switchTo().defaultContent();

       //login to zivame 
       driver.findElement(By.xpath("//a[@href='#myaccount']")).click();

       driver.findElement(By.xpath("//*[@id='auth-email']")).sendKeys("test890@gmail.com");

       driver.findElement(By.xpath(".//*[@id='auth-password']")).sendKeys("test123");


       driver.findElement(By.xpath(".//*[@id='authForm']/div[3]/button")).click();



       //Thread.sleep(3000);

       driver.quit();

    }

}

修改 我得到的错误是:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='auth-email']  

我收到此错误,因为无法在同一页面上关闭两个弹出窗口。 popup id是:<id=materPOP><p id ="close-pop">

另一个弹出式ID详情为:<div class="wrapper"><div id ="webklipper-publisher-widget-container-notification-close-d‌​iv" class="close">

0 个答案:

没有答案