使用selenium执行javascript

时间:2014-10-30 00:20:38

标签: c# selenium-webdriver

我想使用selenium执行javascript。

UI上的JavaScript代码:



<input id="rbSingleFuture" class="rfdRealInput" type="radio" onclick="javascript:setTimeout('__doPostBack(\'rbSingleFuture\',\'\')', 0)" value="rbSingleFuture" name="PaymentTypeGrp" _rfddecoratedid="_rfdSkinnedrbSingleFuture"></input>
&#13;
&#13;
&#13;

我的代码:

&#13;
&#13;
IJavaScriptExecutor js = (IJavaScriptExecutor)_webDriver;
           js.ExecuteScript("onclick=javascript:setTimeout(__doPostBack('rbSingleFuture',''), 0);");    
&#13;
&#13;
&#13;

这不会点击单选按钮。

1 个答案:

答案 0 :(得分:1)

试试这个

IJavaScriptExecutor js = (IJavaScriptExecutor)_webDriver;
js.ExecuteScript("document.getElementById('rbSingleFuture').click();");  

来源:http://www.w3schools.com/jsref/met_html_click.asp