0

I am new to Selenium and just started to use it. I want to open a new browser session in a different window from my script and do not know how to do it.

I tried using the open command and gave the Firefox Url but it opened in the same window.

Any ideas?

4

2 回答 2

0

尝试使用 openWindow 而不是 open。如果您收到 Firefox 阻止弹出窗口的消息,请允许弹出窗口。这可能会打开一个选项卡而不是一个窗口,但这可能会满足您的需要。

于 2010-04-27T21:41:21.153 回答
0
@Test
public void Test01() throws Exception {
openTab("http://www.xyz.com");
}

这将打开一个不同的 Firefox 窗口。然后Handle切换新窗口。

public void trigger(String script, WebElement element) {
((JavascriptExecutor) driver).executeScript(script, element);
}

public Object trigger(String script) {
return ((JavascriptExecutor) driver).executeScript(script);
}

public void openTab(String url) {
String script = "var d=document,a=d.createElement('a');a.target='_blank';a.href='%s';a.innerHTML='.';d.body.appendChild(a);return a";
Object element = trigger(String.format(script, url));
if (element instanceof WebElement) {
WebElement anchor = (WebElement) element;
anchor.click();
trigger("var a=arguments[0];a.parentNode.removeChild(a);", anchor);
} else {
throw new JavaScriptException(element, "Unable to open Window", 1);
}
}
于 2014-02-25T07:02:36.087 回答