最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delphi Edge Browser - trying to enter text into the Find window but it has a different handle than the main window - Stack Overf

programmeradmin11浏览0评论

In Delphi, I'm trying to programattically send text to the Find window in an Edge Browser. After using WinSpector Spy, I see that the Find Window comes up as a "Chrome_WidgetWin_1" object. I would like to know how to get the handle for this object so I can use PostMessage() to send it text directly.

I am able to get the Edge Browser object handle with the following code:

var hchild := GetWindow(MyBrowserGd.EdgeBrowser.Handle, GW_CHILD);
  
ManulifeGd.Edit3.Text := IntToHex(hchild);

I am able to send PostMessage() to the browser without issue.

However, I'm uncertain how to get the handle for the Find window.

I've tried a variety of things, such as using GW_HANDLENEXT, GW_ENABLEDPOPUP in the GetWindow() function, but I'm just not certain what the Edge Browser allows for with regards to these objects.

In Delphi, I'm trying to programattically send text to the Find window in an Edge Browser. After using WinSpector Spy, I see that the Find Window comes up as a "Chrome_WidgetWin_1" object. I would like to know how to get the handle for this object so I can use PostMessage() to send it text directly.

I am able to get the Edge Browser object handle with the following code:

var hchild := GetWindow(MyBrowserGd.EdgeBrowser.Handle, GW_CHILD);
  
ManulifeGd.Edit3.Text := IntToHex(hchild);

I am able to send PostMessage() to the browser without issue.

However, I'm uncertain how to get the handle for the Find window.

I've tried a variety of things, such as using GW_HANDLENEXT, GW_ENABLEDPOPUP in the GetWindow() function, but I'm just not certain what the Edge Browser allows for with regards to these objects.

Share Improve this question edited Feb 5 at 16:11 Remy Lebeau 597k36 gold badges500 silver badges844 bronze badges asked Feb 4 at 23:21 Robert DucheneRobert Duchene 112 bronze badges 2
  • 2 You're way better off either accessing the underlying IWebView2 reference to access the element, or using JavaScript – Dave Nottage Commented Feb 4 at 23:25
  • 1 When dealing with parent/child window hierarchies, use GetDlgItem() or FindWindowEx() to locate a specific child window in a parent window – Remy Lebeau Commented Feb 5 at 16:13
Add a comment  | 

1 Answer 1

Reset to default 0

If the element (the Find window in your example) is identifiable to Javascript (e.g. has a name attribute), then you can use Javascript from Delphi to access and modify it.

For example, let's say you have navigated to the current Embarcadero Quality Portal web page (just using it as an example of a web page with an input field):

EdgeBrowser.Navigate('https://embt.atlassian.net/servicedesk/customer/user/login');

Then, after inspecting the page's source and finding out the details about its input field for Email address:

<input id="user-email" name="user-email" aria-describedby="field-error" type="text" 
autocomplete="email" data-ds--text-field--input="true" class="css-mfjdp3" value="">

Then you can programmatically enter an e-mail into the input box, which has name="user-email", with this:

EdgeBrowser.ExecuteScript(
  'let email_input = document.getElementsByName("user-email"); ' +
  'email_input[0].focus(); ' +
  'document.execCommand(''insertText'', false, ''[email protected]'');');

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论