【问题标题】:A tag is supposed to open a new window,but it didn't work with ieDriver标签应该打开一个新窗口,但它不适用于ieDriver
【发布时间】:2019-01-15 06:54:58
【问题描述】:

以前遇到的一个问题:我用c#&selenium操作Internet explorer的时候,一个A标签,本来是要打开一个新窗口的,但是用ieDriver模拟点击它就不行了。关闭下来ieDriver,成功了。我的水平有限,所以想在这里寻求帮助...

IWebDriver webDriver = new InternetExplorerDriver();
webDriver.Url = "http://emp.sc.ctc.com/#/app/reference/home";
//any website that contains elememt like <a id="1" href="http://www.google.com" target="_blank">click</a>
...
IWebElement webElement = webDriver.FindElementByXpath(By.Xpath("//*[@id=\"1\"]"));
((IJavaScriptExecutor)webDriver).ExecuteScript("arguments[0].click();", webElement);

就这些简单的操作。webElement是&lt;a id="1" href="http://www.google.com" target="_blank"&gt;click&lt;/a&gt;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a id="1" href="http://www.google.com" target="_blank">click</a>

</body>
</html>

,它应该打开一个新的浏览器窗口。

【问题讨论】:

  • 请提供与您的问题相关的任何代码。
  • 在主要问题中更新这些并添加相关的 HTML
  • ~如何更新我发布的问题...
  • 点击编辑更新内容
  • @SilentWatson 您的 ...简化了情况... 可能并不能真正帮助贡献者为您的问题构建规范的答案。而是使用基于文本的相关实际 HTML 更新问题。

标签: c# selenium internet-explorer selenium-iedriver


【解决方案1】:

我通过痛苦的反思解决了这个问题。只要管理员权限运行vs就可以达到想要的效果,也可以管理员权限运行编译好的程序。所以不是代码问题,是环境问题。ieDriver 对此概不负责。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-15
    • 2014-12-26
    • 1970-01-01
    • 2013-04-11
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多