【问题标题】:How i click to button without id?如何在没有 ID 的情况下单击按钮?
【发布时间】:2020-07-28 01:59:35
【问题描述】:

朋友们好,

我正在编写一个应用程序,但出现了问题。我无法点击按钮。请帮助我,谢谢。

我想点击这个按钮:

<input type="button" value="Canlı Derse Başla" onclick="$j('#online_140754').show();$j('#offline_140754').hide();" style="background:#007bff;color:#ffffff;font-weight: bold;border:1px solid #007bff;border-radius: 5px;padding:5px;cursor:pointer;">

我使用了这段代码,但它不起作用。

if (url == "random")
            {
                foreach (HtmlElement nesne in webBrowser1.Document.GetElementsByTagName("input"))
                {
                    if (nesne.GetAttribute("value") == "Canlı Derse Başla")
                    {
                        nesne.InvokeMember("click");
                    }
                }
            }

【问题讨论】:

  • 2020 年 4 月 20 日星期一,向上。

标签: c# php html css button


【解决方案1】:

你可以尝试使用JQuery,其中按钮的点击将基于class而不是id,例如:

$(document).ready(function() {
    $(".btn").click(function() {
        alert("the button was clicked on")
    })   
})

另一种选择是通过标签名称获取元素并查看内部文本,例如:

var buttonCollection = Document.GetElementsByTagName("btn");

foreach (HtmlElement btn in buttonCollection)
{
    if (btn.InnerText == "Click here to do something")
    {
        btn.InvokeMember("click");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-22
    • 2020-01-11
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    相关资源
    最近更新 更多