简体   繁体   English

硒webdriver单击javascript链接

[英]selenium webdriver click javascript link

I am using Selenium-webdriver with C# to test a website. 我在C#中使用Selenium-webdriver测试网站。 I have a issue that when I use Click() to click a link, it doesn't work. 我有一个问题,当我使用Click()单击链接时,它不起作用。 It should open a new window when clicked. 单击时应打开一个新窗口。 I tool a look in the html structure, I found there is a Javascript action on the link. 我在html结构中查看了一下工具,发现链接上有Javascript操作。

The html as following: 的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"/>

What method should I use to click it to open the new window? 我应该使用什么方法单击它以打开新窗口?

I use in some cases click with JavaScript: 我有时在JavaScript中使用click:

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

Where, myElement is a IWebElement . 其中,myElement是IWebElement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM