简体   繁体   English

如何在WebKitBrowser中单击类按钮?

[英]How do you click a class button in WebKitBrowser?

I have this code for a class button: 我有一个用于类按钮的代码:

<a class="bid-button-link button-big" href="/bid.php?scheck=fb7520ee7496e528b90117fa46dcb2ad&id=4042" title="4042"></a>

I could normally do this with a regular browser: 我通常可以使用常规浏览器执行此操作:

HtmlElementCollection elc = this.webBrowser1.Document.GetElementsByTagName("a");  
foreach (HtmlElement el in elc)  
{  
    if (el.GetAttribute("class") == "bid-button-link button-big") 
    {  
        el.InvokeMember("click");  
    }  
} 

But since I am using a WebKitBrowser , I can't do that. 但是由于我使用的是WebKitBrowser ,所以我不能这样做。 I make a can get the button with this code: 我用这个代码可以得到按钮:

foreach (Node bidButton in webBrowser1.Document.GetElementsByTagName("a"))
{
    if (((Element)bidButton).GetAttribute("class") == "bid-button-link button-big")
    {
        //Code to click the button
    }
}

But I don't have any way to click the button, because WebKitBrowser does not have an option to .InvokeMember("Click") 但是我没有任何方法可以单击按钮,因为WebKitBrowser没有.InvokeMember("Click")

Is there any way to click the button even though it is a Class Button ? 即使它是“ Class Button也可以单击该按钮吗?

As you know, In the normal framework of Visual C# (WebBrowser) you can do something like this: 如您所知,在Visual C#(WebBrowser)的常规框架中,您可以执行以下操作:

WebBrowser.Document.GetElementById("the ID").click()

But in WebKitBrowser the click() method is not defined, you can also emulate the JavaScript code of the click method with this function: 但是在WebKitBrowser中,click()方法未定义,您还可以使用以下函数来模拟click方法的JavaScript代码:

WebBrowser.StringByEvaluatingJavaScriptFromString("Document.GetElementById('the ID').click();")

Hope this help you! 希望这对您有所帮助!

Edited: 编辑:

change your code to this: 将您的代码更改为此:

foreach (Node bidButton in webBrowser1.Document.GetElementsByTagName("a"))
{
    if (((Element)bidButton).GetAttribute("class") == "bid-button-link button-big")
    {
        bidButton.SetElement("id","Bidbutton")
        WebBrowser.StringByEvaluatingJavaScriptFromString("Document.GetElementById('BidButton').click();")
    }
}

The suggestions above worked for me, but only after I first called focus(), if you're having trouble, try that. 上面的建议对我有用,但是只有在我第一次调用focus()之后,如果您遇到问题,请尝试一下。

Eg: 例如:

webKitBrowser.StringByEvaluatingJavaScriptFromString("document.getElementsByTagName('input')[7].focus();") 

webKitBrowser.StringByEvaluatingJavaScriptFromString("document.getElementsByTagName('input')[7].click();")

How about bidButton.click()? 那bidButton.click()呢? Don't know which webkit bindings you are using, but click function is available in most of the implements. 不知道您使用的是哪种Webkit绑定,但是在大多数工具中都可以使用click功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM