![](/img/trans.png)
[英]c# asp.net how can i change the image url of button (it's type is image ) when i click the button in gridview
[英]How can i click on the image button when i know only div id and img src in C#?
我在Stack Overflow上搜索解決方案,但沒有找到,所以這是一個新問題。 我正在制作程序,它將使您登錄網絡游戲並單擊以開始。 這是問題。 我正在嘗試一些代碼,例如:
HtmlElementCollection startButton = mapWebBrowser.Document.All;
foreach (HtmlElement start in startButton)
{
if (start.GetAttribute("src") == "/do_img/global/text_tf.esg?l=cs&s=16&t=header_start&f=eurostyle_tbla&color=white&bgcolor=green&h=18")
{
start.InvokeMember("click");
}
}
這行不通。 你能幫助我嗎? 圖像按鈕的代碼為:
<div id="header_start_btn" >
<img src="/do_img/global/text_tf.esg?l=cs&s=16&t=header_start&f=eurostyle_tbla&color=white&bgcolor=green&h=18" />
</div>
這里有幾件事情要考慮。 您應該在Form_Load事件中設置源:
private void Form1_Load(object sender, EventArgs e)
{
mapWebBrowser.Url = new Uri("...");
}
然后,您需要等待文檔呈現,然后使用以下代碼進行查找:
private void mapWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement imageTag = mapWebBrowser.Document.GetElementById("header_start_btn").Children[0];
}
剛剛測試了一下,就可以了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.