Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SeleniumWebDriver单击javascript链接_C#_Javascript_Selenium - Fatal编程技术网

C# SeleniumWebDriver单击javascript链接

C# SeleniumWebDriver单击javascript链接,c#,javascript,selenium,C#,Javascript,Selenium,我正在使用SeleniumWebDriver和C#来测试一个网站。我有一个问题,当我使用Click()单击链接时,它不起作用。它应该在单击时打开一个新窗口。我查看了一下html结构,发现链接上有一个Javascript操作 html格式如下所示: <span class="new_doc"> <a style="cursor: pointer;" onclick="javascript:popwinnewproject('pc.aspx?page=docnew2tree&a

我正在使用SeleniumWebDriver和C#来测试一个网站。我有一个问题,当我使用
Click()
单击链接时,它不起作用。它应该在单击时打开一个新窗口。我查看了一下html结构,发现链接上有一个Javascript操作

html格式如下所示:

<span class="new_doc">
  <a style="cursor: pointer;" onclick="javascript:popwinnewproject('pc.aspx?page=docnew2tree&j=P2&grp=actv&t=');">
    <img title="new doc" src="http://local:8080/res/icon/new-doc.png"/>


我应该使用什么方法单击它来打开新窗口?

我在某些情况下使用JavaScript单击:

IJavaScriptExecutor executor = (IJavaScriptExecutor).driver;
executor.ExecuteScript("arguments[0].click();", myElement);

其中,myElement是一个IWebElement。

在JavaScript中,
OnClick
事件用于在按钮、链接等。。。单击。所以它肯定会和一个元素相连。发布更多HTML代码。您如何识别此链接?添加了更多HTML代码addvar button=BrowserDriver.Driver.findelelement(By.XPath(“//*[@id='barbutton']]///img[@title=”+btn+']/..);按钮。单击();