Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger a change event in HtmlInput element ? #18

Closed
mediabuff opened this issue Oct 11, 2023 · 3 comments
Closed

How to trigger a change event in HtmlInput element ? #18

mediabuff opened this issue Oct 11, 2023 · 3 comments

Comments

@mediabuff
Copy link

Hi,
I change the input text programmatically like


  var devToolsContext = await webView.CoreWebView2.CreateDevToolsContextAsync();
  inputText = (HtmlInputElement)await devToolsContext.QuerySelectorAsync(".custom-input");
 await inputText.SetValueAsync("hello");

But unfortunately this does not trigger a change event

@mediabuff
Copy link
Author

For now, I ended up doing the following. Better alternatives are welcome:

var devToolsContext = await webView.CoreWebView2.CreateDevToolsContextAsync();
inputText = (HtmlInputElement)await devToolsContext.QuerySelectorAsync(".custom-input");
await inputText.SetValueAsync("hello");
await webView.CoreWebView2.ExecuteScriptAsync("document.querySelector('.custom-input').dispatchEvent( new Event('input', { bubbles: true }))");

@mediabuff
Copy link
Author

mediabuff commented Oct 11, 2023

Also, this is very flaky. I get an excepton in Microsoft.Web.WebView2.Core.CoreWebView2


CallDevToolsProtocolMethodAsync
with methodName == Page.enable and parametersAsJson string.empty

@amaitland
Copy link
Collaborator

The API is based on puppeteer-sharp, so you achieve many of the things in the same way. You can type into a inputbox to simulate user input.

//Type text in an input field
await element.TypeAsync("Welcome to my Website!");

//Scroll Element into View (if needed)
//Can optional specify a Rect to be scrolled into view, relative to the node's border box,
//in CSS pixels. When omitted, center of the node will be used
await element.ScrollIntoViewIfNeededAsync();

//Click The element
await element.ClickAsync();

Also, this is very flaky. I get an excepton in Microsoft.Web.WebView2.Core.CoreWebView2

Make sure you have only a single contract at a time. See #11 (comment)

@ChromiumDotNet ChromiumDotNet locked and limited conversation to collaborators Oct 12, 2023
@amaitland amaitland converted this issue into discussion #20 Oct 12, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants