Cef 浏览器 Wpf 探索 dom、查找元素和更改值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29658730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cef Browser Wpf explore the dom, find elements and change values
提问by Alain BUFERNE
Further to a post (CefSharp load a page with browser login).
I implemented the IRequestHandlerinterface and the different methods, particularly the GetAuthCredentialswhere I show a dialog and recover user and password and passing it to the event handler.
Now I want to access to the dom where I get several framesetwith differents framesand I'm interested in one framewhich I know the nameAtribute.
Inside this frameI need to get list of different type of input, selectetc...
In my app I have a button which I use to set values of the different elementsdepending if they are present on the displayed page.
PROBLEM is I don't see any way of getting the document, the framescollection etc....
进一步的帖子(CefSharp 加载带有浏览器登录的页面)。我实现了IRequestHandler接口和不同的方法,特别是GetAuthCredentials在我显示对话框并恢复用户和密码并将其传递给事件处理程序的地方。现在我想访问 dom,在那里我得到了几个frameset不同的frames,我对frame我知道nameAtribute 的一个感兴趣。在这里面,frame我需要获取不同类型的列表input,select等等......在我的应用程序中,我有一个按钮,我用它来设置不同的值,elements具体取决于它们是否出现在显示的页面上。问题是我看不到任何获取document、frames集合等的方法......
回答by amaitland
CefSharpdoesn't expose the underlying DOM, and is unlikely to see http://magpcss.org/ceforum/viewtopic.php?f=6&t=10652&p=19533#p16750
CefSharp不暴露底层DOM,不太可能看到http://magpcss.org/ceforum/viewtopic.php?f=6&t=10652&p=19533#p16750
Your best bet is to use EvaluateScriptAsyncand a combination of Javascript Binding
你最好的选择是使用EvaluateScriptAsync和组合Javascript Binding
https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#2-how-do-you-call-a-javascript-method-that-return-a-resulthttps://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#3-how-do-you-expose-a-net-class-to-javascript
https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#2-how-do-you-call-a-javascript-method-that-return-a-result https://github.com /cefsharp/CefSharp/wiki/Frequently-asked-questions#3-how-do-you-expose-a-net-class-to-javascript
If you absolutely must have DOMaccess and cannot invent your way to a solution then CefGluemight be a better choice for you. (I should point out that the DOMcan only be accesses in the Renderprocess, and as such calls needed to be passed to the Browserprocess though IPC, so it isn't a trivial task).
如果您绝对必须有权DOM访问并且无法发明解决方案,那么CefGlue对您来说可能是更好的选择。(我应该指出,DOM只能在Render进程中访问,因此需要将调用传递给Browser进程IPC,因此这不是一项微不足道的任务)。

