selenium webdriver:如何在 C# 中处理 javascript onclick [英] selenium webdriver: how to deal with javascript onclick in C#

查看:22
本文介绍了selenium webdriver:如何在 C# 中处理 javascript onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 selenium Web 驱动程序 C# 测试网站.我最初的目的是检查返回 200 的 HttpWebResponse.但是,该按钮是一个 javascript onclick 事件.我想知道是否有人过去有过如何处理这种情况的经验.这是按钮的 HTML:

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>

推荐答案

试试这个:

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.

这篇关于selenium webdriver:如何在 C# 中处理 javascript onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆