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

11,521

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.

Share:
11,521
Selenium User
Author by

Selenium User

Updated on July 25, 2022

Comments

  • Selenium User
    Selenium User almost 2 years

    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>