简体   繁体   English

使用Selenium Java在浏览器中的两个窗口之间切换

[英]switch between two windows in browser using Selenium java

I'm trying to switch between windows and put an accountant to find out if the Selenium found the second window , but does not find it , note that he sees only 01 window , which is the Father window. 我试图在各个窗口之间切换,并请一位会计师找出Selenium是否找到了第二个窗口,但是没有找到它,请注意,他仅看到01窗口,这是父亲窗口。

how do I find It the second window and switch to It? 如何在第二个窗口中找到它并切换到它?

I use: selenium-server-standalone-2.48.2 + Eclipse + Java 1.8 我使用:selenium-server-standalone-2.48.2 + Eclipse + Java 1.8

I tried this: 我尝试了这个:

    //Get all window handles
                Set<String> allHandles = driver.getWindowHandles();

                //count the handles Here count is=2
                System.out.println("Count of windows:"+allHandles.size());      

                //Get current handle or default handle
                String currentWindowHandle = allHandles.iterator().next();
                System.out.println("currentWindow Handle"+currentWindowHandle);

                //Remove first/default Handle
                allHandles.remove(allHandles.iterator().next());

                //get the last Window Handle
                String lastHandle = allHandles.iterator().next();
                System.out.println("last window handle"+lastHandle);

                //switch to second/last window, because we know there are only two    windows 1-parent window 2-other window(ad window)
                driver.switchTo().window(lastHandle);
                System.out.println(driver.getTitle());
                driver.findElement(By.tagName("body")).click();

message on the console: 控制台上的消息:

控制台上的消息

我遇到了IE 11的类似问题。通过检查IE设置中所有区域的启用保护模式设置来解决此问题。

暂无
暂无

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

相关问题 如何使用Selenium java在浏览器中的两个窗口之间切换 - How to switch between two windows in browser using Selenium java 无法使用Selenium WebDriver在两个浏览器窗口之间切换 - Unable to switch between two browser windows using Selenium WebDriver 如何在 java 中使用 selenium 在两个或多个 chrome 浏览器 windows(不是标签)之间切换? - How to switch between two or mutlple chrome browser windows (Not tabs) using selenium in java? Selenium Web驱动程序| Java | 无法在Firefox浏览器窗口之间切换 - Selenium web driver | java | unable to switch between firefox browser windows 使用带有 Java 的 Selenium WebDriver 在浏览器选项卡之间切换 - Switch between browser tabs using Selenium WebDriver with Java 如何使用带有Java的Selenium WebDriver在Chrome中的Windows之间切换? - How to switch between windows in Chrome using Selenium WebDriver with Java? 如何使用 Selenium Java 在两个浏览器选项卡/窗口之间获取活动的 window 标题 - How to get an active window title between two browser tabs/windows using Selenium Java 使用Selenium Webdriver在浏览器窗口之间切换 - Switching between browser windows using Selenium Webdriver 我可以在 java 中使用 selenium webdriver 通过页面标题在 windows 之间切换吗? - Can i switch between windows by its page title using selenium webdriver in java? 如何在 selenium 测试中使用 java 代码检测两个 chrome 浏览器 windows 之间的音频连接? - How to detect audio connection between two chrome browser windows using jave code in selenium tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM