【发布时间】:2023-04-09 08:22:01
【问题描述】:
请看下面这段html代码来理解:
<input type="submit" name="send" class="button" value="Send" onclick="return ussd_send()">
<input type="submit" name="send" class="button" value="Disconnect" onclick="return ussd_exit()">
我想点击Send按钮,但是我使用的代码没有任何效果:
webView21.ExecuteScriptAsync("document.getElementsByClassName('return ussd_send()').click();");
【问题讨论】:
-
return ussd_send()不是 INPUT 元素的className,而是button。可以使用 TAG 名称和value属性将其单出来。 -
你能给我完整的代码吗?下面我也在尝试但不工作! webView21.ExecuteScriptAsync("document.getElementByName('send').click();");
-
实际上是
getElementsByName,它将返回所有具有该名称的元素(这里是两个)。要返回第一个,您可以在其后添加[0],如下所示:webView21.ExecuteScriptAsync("document.getElementsByName('send')[0].click();");。 -
谢谢它的工作哇!!!
标签: c# winforms webview2 execute-script