Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium webdriver: how to deal with javascript onclick in C#

I'm testing a website using selenium web driver C#. My intention originally is to check the HttpWebResponse that returns 200. However, the button is a javascript onclick event. I'm wondering if anyone has past experience about how to deal with this situation. Here's the HTML for the button:

<td>
<input id="ctl00_ContentPlaceHolder1_ExportPACEButton" type="submit" tabindex="-1" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$ExportPACEButton", "", true, "", "", false, false))" value="Export as PACE File" name="ctl00$ContentPlaceHolder1$ExportPACEButton"/>
</td>
like image 499
Selenium User Avatar asked Mar 05 '13 19:03

Selenium User


1 Answers

Try something like this:

public void JavaScriptClick(IWebElement element)
{
    IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
    executor.ExecuteScript("arguments[0].click();", element);
}

And driver is the driver you used in other place.

like image 90
xelless Avatar answered Nov 09 '22 08:11

xelless