在下面的代码中,
//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 :(得分:0)
尝试IE的以下方法:
<强>爪哇:强>
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);