2017-04-25 147 views
0

在下面的代码多个窗口,处理在IE和Chrome浏览器

//Element clicked in parent window 
driver.findElement(By.id("ID")).click(); 

//Once after clicking the ID, system takes the user to a different tab in chrome and launches an external link 
//In IE the same external link will launch in a new browser which is different from chrome behavior 

Iterator<String> browsers = driver.getWindowHandles().iterator(); 
while(browsers.hasNext()){ 
driver.switchTo().window(browsers.next()); 

//Element to be clickable in the child window or external site 
driver.findElement(By.xpath(".//button")).click(); 

谁能帮我我们如何处理的情况下,我想一些东西,无论是在IE和Chrome工作。目前上面的代码在chrome中工作,但不在IE中,因为外部链接在新浏览器中打开。我不能够处理的情况下

回答

0

尝试使用IE浏览器下面的方法:

的Java:

DesiredCapabilities cap = DesiredCapabilities.internetExplorer(); 
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); 
cap.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING,true); 
cap.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR,"accept"); 
cap.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true); 
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,""); 
WebDriver dr = new InternetExplorerDriver(cap); 

C#:

var options = new InternetExplorerOptions(); 
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; 
options.EnsureCleanSession = true; 
options.IgnoreZoomLevel = true; 
options.UnhandledPromptBehavior = UnhandledPromptBehavior.Accept; 
options.RequireWindowFocus = true; 
options.InitialBrowserUrl = ""; 
string iedriver = TestContext.DataRow["IEDRIVER"].ToString(); 
dr = new InternetExplorerDriver(iedriver,options); 
相关问题