[英]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.