Search code examples
javascriptvb.netcefsharp

Click on the Search box to get it active with CefSharp


May be some body know why I can't get fire MouseClick event.

This is my HTML markup:

<app-invoice-details-customer-search _ngcontent-ydd-c36="" class="customer-search-input" _nghost-ydd-c40="">
<div _ngcontent-ydd-c40="">
<div _ngcontent-ydd-c40="" class="form-group search-group">
<input _ngcontent-ydd-c40="" aria-label="Number" class="form-control mat-autocomplete-trigger" name="searchBox" type="search" placeholder="Valitse asiakas" autocomplete="off" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-haspopup="true">
<span _ngcontent-ydd-c40="" class="search-icon"></span>
<span _ngcontent-ydd-c40="" class="clear-search"></span>
<mat-autocomplete _ngcontent-ydd-c40="" class="">
<!---->
</mat-autocomplete>
</div>
</div>
</app-invoice-details-customer-search>

My target is to place mouse click on "customer-search-input". After click, input field have to be active with cursor on it, which after I want to sendKeyEvents to write "1159". Unfortunately it doesn't work if I just send to this field value, because web page after each write number make search on the own database for filtered customers. So, I tried three basic ways to achieve it. One of them with JavaScript:

var coordinates = document.getElementsByClassName("customer-search-input")[0].getBoundingClientRect();
var ev = new MouseEvent('click', {
    'view': window,
    'bubbles': true,
    'cancelable': true,
    'screenX': coordinates.x,
    'screenY': coordinates.y
});

var el = document.elementFromPoint(coordinates.x, coordinates.y);

el.dispatchEvent(ev);

This code almost work on console panel and I'm sure that it made clicks on the right place, because of previously added event listener. But nothing happens. Second step with focus() also doesn't help.

document.getElementsByClassName("customer-search-input")[0].focus();

Also tried third step with Cefsharp browser make click on there with exact coordinates and again won't work.

browser.GetBrowser().GetHost().SendMouseMoveEvent(750, 306, False, CefEventFlags.None)
Thread.Sleep(100)
browser.GetBrowser().GetHost().SendMouseClickEvent(750, 306, MouseButtonType.Left, False, 1, CefEventFlags.None)
Thread.Sleep(100)
browser.GetBrowser().GetHost().SendMouseClickEvent(750, 306, MouseButtonType.Left, True, 1, CefEventFlags.None)

What I noticed. When code is running and if I make by my self click on the browser field, this page load with search field active by default. I tried also make click programmatically before page loaded and this doesn't help.

Where is the problem? It looks that clicks made, but field is still not active. May it be problem in ChromiumBrowser settings? Or can I try some other ways?


Solution

  • Answer for my question is very fun. After page load Thread.Sleep(500) was very short wait time. When I changed it to 2000 al work as it have to be.