2017-04-25 191 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); 
相關問題