gpt4 book ai didi

c# - WebBrowser 控件 - 按类型获取元素?

转载 作者:太空狗 更新时间:2023-10-30 01:10:01 26 4
gpt4 key购买 nike

我需要在 C# 中按类型获取元素,HTML 如下所示:

<button type="submit" class="orangeBtn">Send Invitations</button>

我希望它能够在我可以调用(“单击”)它的位置,但它在 C# 中似乎不起作用。我当前的代码是:

HtmlElement m_SubmitField = m_Browser.Document.All["orangeBtn"];

if (m_SubmitField != null)
m_SubmitField.InvokeMember("click");

是否有替代的工作方式来做到这一点?

这不是我的服务器,所以我不能编辑 HTML 或添加 jquery。

我正在制作一个自动应用程序来向我想加入的 friend 发送邀请,但是他们制作了没有 id 或名称的按钮,如上所示,所以无论如何都要在 C# 中调用(“点击”)使用不同的方法?

谢谢。

最佳答案

您可以使用 GetElementsByTagName

var elements = m_Browser.Document.GetElementsByTagName("button");
foreach (HtmlElement element in elements)
{
// If there's more than one button, you can check the
//element.InnerHTML to see if it's the one you want
if (element.InnerHTML.Contains("Send Invitations"))
{
element.InvokeMember("click");
}
}

关于c# - WebBrowser 控件 - 按类型获取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5603164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com