简体   繁体   中英

WebDriver- Handle HTML Pop-Up

I am Trying to get past the Window just above the Login Page Note since html Class names are dynamic, I am Not Holding them in my xpath

WebSite --> seatseller.travel // Objective --> Click the Cancel button of the Offer page (It only shows ONCE and saves in Local Storage of Browser as Property) Note : since html Class names are dynamic, I am Not Holding them in my xpath

I have tried all viable solutions as 1) Trying to Hold Frames ; 2) Trying it as Alert failed..

Any Working solution will be a Gift

Thanks in Advance

public class dhmaka {

    /**
     * @param args
     * @throws InterruptedException 
     * @throws IOException 
     */
    public static void main(String[] args) throws InterruptedException, IOException {



        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        driver.get("https://in3.seatseller.travel/");
        driver.manage().window().maximize();
         // Exit Summer Dhamaka Frame ..
        String currentWindow = driver.getWindowHandle();

        Set<String> handles = driver.getWindowHandles();
        Iterator<String> iterator = handles.iterator();
        String subWindowHandler = null;
        while (iterator.hasNext()){
            subWindowHandler = iterator.next();
        }
        driver.switchTo().window(subWindowHandler);             
        System.out.println(subWindowHandler);
        driver.switchTo().window(subWindowHandler);                 
        driver.findElement(By.name("//div[@class = 'popupContent']/div/div[2]")).click();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.close();
    }

}

You should be using By.XPath() instead of By.name() as what you have given is actually XPATH.

That should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM