[英]How i click to button without id?
Hello my friends,朋友们大家好,
I'm coding a app but there is a problem.我正在编写一个应用程序,但有一个问题。 I couldn't click to button.
我无法点击按钮。 Please help me, thanks.
请帮助我,谢谢。
I want to click this button:我想点击这个按钮:
<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;">
I used this code but it didn't work.我使用了这段代码,但它没有用。
if (url == "random")
{
foreach (HtmlElement nesne in webBrowser1.Document.GetElementsByTagName("input"))
{
if (nesne.GetAttribute("value") == "Canlı Derse Başla")
{
nesne.InvokeMember("click");
}
}
}
You can try with JQuery, in which the clicking of the button will be based on the class instead of the id, such as:您可以尝试使用 JQuery,其中按钮的单击将基于 class 而不是 id,例如:
$(document).ready(function() {
$(".btn").click(function() {
alert("the button was clicked on")
})
})
Another option is to get the elements by the tag name and looking at the inner text, for example:另一种选择是通过标签名称获取元素并查看内部文本,例如:
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.