[英]How i click to button without id?
朋友們大家好,
我正在編寫一個應用程序,但有一個問題。 我無法點擊按鈕。 請幫助我,謝謝。
我想點擊這個按鈕:
<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");
}
}
}
您可以嘗試使用 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");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.