How to use HTML elements from CEF

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

How to use HTML elements from CEF

Postby lkitrossky » Wed Apr 22, 2015 4:48 pm

Hi! I am building unit tests in CEF. Suppose, CEF browser opens some web page. Now I want to run some unit tests that will use HTML of the page. I succeeded to do it this way:
Code: Select all
class MyTestHandler : public TestHandler{
/*some lines*/
void OnLoadEnd(CefRefPtr<CefBrowser> browser,
                 CefRefPtr<CefFrame> frame,
                 int httpStatusCode) override {
             browser->GetMainFrame()->ExecuteJavaScript("document.getElementById('id').value = 'myvalue';", CefString(), 0);

My question is, may I reach and use HTML elements without JavaScript, some straight path to DOM from browser? I found something like

Code: Select all
browser->GetMainFrame()->VisitDOM...
CefRefPtr<CefDOMNode> docNode = document->GetDocument();

but cannot understand how to reach DOM object from browser or frame in OnLoadEnd or another. Thanks, LK
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: How to use HTML elements from CEF

Postby magreenblatt » Thu Apr 23, 2015 2:21 am

lkitrossky wrote:may I reach and use HTML elements without JavaScript, some straight path to DOM from browser?

No, JavaScript is the way to go. You can also simulate mouse/keyboard input using the CefBrowserHost::Send*Event methods. Or use ChromeDriver: https://bitbucket.org/chromiumembedded/ ... eDriver.md
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to use HTML elements from CEF

Postby lkitrossky » Thu Apr 23, 2015 5:40 am

Thanks, but ExecuteJavaScript has no return value and we cannot know, if JavaScript code succeeded. Say, I need to click OK on some dialog box. How I to know that the dialog really closed? At least I need some way to enumerate DOM elements and check, if the dialog disappeared from the list. How can I do it?
Maybe can Chrome Driver you mentioned do the work? But it is a totally different direction needs Java, while I need unit tests from inside C++. Great thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: How to use HTML elements from CEF

Postby magreenblatt » Thu Apr 23, 2015 5:53 am

ChromeDriver provides much of the functionality that you're looking for and can be used from different languages (Java, Python, Ruby, etc). If you want to do everything in C++ then you will need to write the test harness yourself. For more information on creating JavaScript/C++ bindings see https://bitbucket.org/chromiumembedded/ ... gration.md.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: How to use HTML elements from CEF

Postby lkitrossky » Fri Apr 24, 2015 7:37 am

1. Can I use IPC to send message from renderer to browser that call browser->GetMainFrame()->ExecuteJavaScript succeeded nd DOM changed?
2. Suppose we use ChromeDriver: https://bitbucket.org/chromiumembedded/ ... eDriver.md. The reference you provided seems promising. Is there is a sample like you pointed to:
Code: Select all
WebElement searchBox = driver.findElement(By.name("q"));
       searchBox.sendKeys("ChromeDriver");

but in Python instead of Java?
Great thanks, Levi
lkitrossky
Mentor
 
Posts: 66
Joined: Tue Mar 24, 2015 7:26 am

Re: How to use HTML elements from CEF

Postby magreenblatt » Fri Apr 24, 2015 7:43 am

lkitrossky wrote:Suppose we use ChromeDriver: https://bitbucket.org/chromiumembedded/ ... eDriver.md. The reference you provided seems promising. Is there is a sample [...] in Python instead of Java?

Yes, see https://sites.google.com/a/chromium.org ... ng-started
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 39 guests