调用Click Cefsharp VB [英] Invoke Click Cefsharp VB

查看:175
本文介绍了调用Click Cefsharp VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟对Visual Studio vb项目中的Web浏览器元素的单击或按键操作。
我已经找到了针对Visual Studio内置的webbrowser对象执行此操作的方法,但是我使用的是cefsharp浏览器,因此
weBrowser.Document.GetElementById('id' ).InvokeMember( Click)不起作用,因为cefsharp不允许 .Document 。因此,我要重申的问题是,如何使用vb模拟对cefsharp Web浏览器的单击?感谢您的帮助,并祝您有愉快的一天。

I would like to simulate a click or keypresses to a web browser element that is on my visual studio vb project. I have found ways to do it for the webbrowser object built-in to visual studio, but I am using the cefsharp browser, so weBrowser.Document.GetElementById('id').InvokeMember("Click") would not work, because cefsharp doesn't allow .Document. So my question, to reiterate, is, how would I use vb to simulate a click on my cefsharp webbrowser? Any help is appreciated, and have a nice day.

编辑:我一直在编写以下代码:

Dim elementID As String = myBtn
Dim click As String = Click
browser.ExecuteScriptAsync( Document.All(elementID).InvokeMember(click))

,但我不确定它是否可以工作或如何使用elementID部分(我不确定此处可以使用哪种Web元素)。也许这些额外的信息会有所帮助。

I've been working on this code: Dim elementID As String = "myBtn" Dim click As String = "Click" browser.ExecuteScriptAsync("Document.All(elementID).InvokeMember(click)") but I am not sure if it will work or how to use the elementID part (I am not sure what kind of web elements can go here). Maybe this extra information will help.

推荐答案

使用 ExecuteScriptAsync 将执行JavaScript针对Chrome引擎,因此您必须向该函数发送有效的JavaScript。以下代码显示了如何使用DuckDuckGo开始搜索

Using ExecuteScriptAsync will execute JavaScript against the Chrome engine, so you would have to send valid JavaScript to this function. The following code shows how you could start a search using DuckDuckGo

Imports System.Threading
Imports CefSharp
Imports CefSharp.WinForms

Public Class Form1
  Private _browser As New ChromiumWebBrowser()


  Sub New()
    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    _browser.Top = 10
    _browser.Left = 10
    _browser.Width = 600
    _browser.Height = 400
    Controls.Add(_browser)
  End Sub


  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    _browser.Load("https://duckduckgo.com/")
    'for simplicity just wait until page is downloaded, should be handled by LoadingStateChanged
    Thread.Sleep(3000)
    Dim jsScript As String = <js><![CDATA[
document.all("q").value = "stack overflow";
document.all("search_button_homepage").click();
                             ]]></js>.Value
    _browser.ExecuteScriptAsync(jsScript)
  End Sub


End Class

这篇关于调用Click Cefsharp VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆