简体   繁体   English

WebDriver-处理HTML弹出窗口

[英]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 我试图越过登录页面注上方的窗口,因为html类名称是动态的,所以我没有将它们保存在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 WebSite-> seateller.travel //目标->单击“报价”页面的“取消”按钮(它仅显示一次,并以属性形式保存在浏览器的本地存储中)注意:由于html类名是动态的,因此我不持有在我的xpath中

I have tried all viable solutions as 1) Trying to Hold Frames ; 我尝试了所有可行的解决方案,例如:1)尝试固定框架; 2) Trying it as Alert failed.. 2)尝试警报失败。

Any Working solution will be a Gift 任何有效的解决方案将是一份礼物

Thanks in Advance 提前致谢

public class dhmaka { 公共课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. 您应该使用By.XPath()而不是By.name()因为您给出的实际上是XPATH。

That should work. 那应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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