简体   繁体   English

如何在Selenium2(Webdriver)中处理POPUP浏览器?

[英]How to Handle POPUP browser in Selenium2(Webdriver)?

I'm using Selenium2 (Webdriver). 我正在使用Selenium2(Webdriver)。

Well, I have a Problem. 好吧,我有一个问题。

I have a A Browser. 我有一个浏览器。 When I click one button in A Browser, Another popup browser(B) is open. 当我在A浏览器中单击一个按钮时,另一个弹出浏览器(B)打开。

And, The process what I have to do in B browser is done, B browser wasn't close. 并且,我必须在B浏览器中完成的过程已经完成,B浏览器没有关闭。 But, this is not my problem. 但是,这不是我的问题。 B browser is originally Designed this way. B浏览器本来就是以此方式设计的。

my problem is .. 我的问题是..

After B browser's process is finished, when I tried to find out C element in A browser, So B browser wans't closeed, that I can't find out C element. B浏览器的处理完成后,当我尝试在A浏览器中查找C元素时,B浏览器无法关闭,我找不到C元素。 because Selenium tried to find out C element in B browser. 因为Selenium试图在B浏览器中找出C元素。

I just want... 我只是想...

When I do something in Browser B, Browser B has a Handle. 当我在浏览器B中执行某项操作时,浏览器B具有一个句柄。 and the Process in Browser is done, the handle must moving in A Browser. 并且浏览器中的处理完成后,手柄必须在浏览器中移动。

How can I? 我怎样才能? Please Help me. 请帮我。

Here is the sample code for switching between the Windows: With windows handle we can switch between windows. 这是在Windows之间切换的示例代码:使用Windows句柄,我们可以在Windows之间切换。

WebDriver driver=new FirefoxDriver();
//First navigating to Yahoo site
driver.get("http://www.Yahoo.com");
//Capturing the window handle
String strMainWindowHandle=driver.getWindowHandle();
//For better understanding printing the page title
System.out.println(driver.getTitle());

//Now opening a new window
driver.findElement(By.xpath("//body")).sendKeys(Keys.CONTROL+"n");
Set<String> winHandles=driver.getWindowHandles();
for(String handle:winHandles)
    driver.switchTo().window(handle);
//Navigating to Google site with new window i.e new window handle 
driver.get("http://www.google.com");
//For better understanding printing the page title
System.out.println(driver.getTitle());

//Switching back control to main Window which captured earlier
driver.switchTo().window(strMainWindowHandle);
System.out.println(driver.getTitle());

Once you come back to your main window handle you can perform Click or whatever u want. 返回主窗口句柄后,您可以执行“单击”或任何您想要的操作。

暂无
暂无

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

相关问题 如何使用 Selenium Webdriver 处理浏览器身份验证弹出窗口 - How to Handle Browser Authentication popup using Selenium Webdriver 如何使用Java中的Selenium WebDriver处理身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver in Java 如何处理硒webdriver中的弹出窗口(不警报)? - how to handle popup in selenium webdriver (which is not alert)? 当浏览器窗口未聚焦时,使用Java的Selenium2(WebDriver)失败 - Selenium2 (WebDriver) using Java fails when browser window is not focused 无法使用带有 Java 的 Selenium2 (Webdriver) 启动 IE 浏览器 - Not able to launch IE browser using Selenium2 (Webdriver) with Java 如何使用Java在Selenium2中捕获屏幕截图,需要在最小化浏览器时捕获带有其父窗口(浏览器)的弹出窗口 - How to capture Screenshot in Selenium2 using Java, need to capture popup window with its parent window(Browser) when browser is minimized 如何使用Java在Selenium2(Webdriver)中键入Gmail正文文本 - How to type Gmail Body text in Selenium2 (Webdriver) using Java 如何使用Java通过Selenium WebDriver处理fancybox弹出窗口 - How to handle fancybox popup through Selenium WebDriver using Java 如何使用Selenium WebDriver处理“使用Google登录”弹出窗口 - How to handle 'Log in with Google' popup window using Selenium WebDriver 如何使用Selenium WebDriver处理Excel下载弹出窗口 - How to handle Excel download popup using Selenium WebDriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM