Simulate a keystroke in an invisible object in a C # web browser

I am currently working in an application that needs to navigate a web page and recall data about products, prices, ... with a webbrowser object in .net 3.5.

The problem is that there are several fields on the page with a script clause in ajax, and I cannot just change the innerText property because the script also stores the codes in a hidden input field.

I need a way to simulate the input in this field, and then send the "Enter" key or run an ajax script, and then send the "Enter" key or some other ways to do this.

+3
source share
4 answers
+3

script, : script, InvoekScript :

myWebBrowser.Document.InvokeScript("script-name",null);

.

, , , script, :

HtmlElement element=myWebBrower.Document.GetElementById("element-name")[0];
element.InvokeMember("click");
+2

WebBrowser.

HTML: , "", . :

webbrowser1.Navigate("javascript:function%20E(){f0=document.forms[0];f0['login'].value='foo';}E()")
webbrowser1.Navigate("javascript:document.forms[0].submit()")

, HTML.

** Flash: ** - flash, , . SendKeys , , . Windows (, "f" ):

Dim c as char = "f"c
Dim classname As New System.Text.StringBuilder(100)
Dim ExplorerHandle As IntPtr = webbrowser1.Handle
GetClassNameA(ExplorerHandle, classname, classname.Capacity)
Do While classname.ToString <> "Internet Explorer_Server"
    ExplorerHandle = GetWindow(GetExplorerHandle, GetWindow_Cmd.GW_CHILD)
    GetClassNameA(ExplorerHandle, classname, classname.Capacity)
Loop

PostMessageA(ExplorerHandle, WM_Constants.WM_KEYDOWN, IntPtr.Zero, IntPtr.Zero)
PostMessageA(ExplorerHandle, WM_Constants.WM_KEYUP, CType(VkKeyScanA(CType(Asc(c), Byte)), IntPtr), IntPtr.Zero)

PostMessage, GetClassName, GetWindow .. pinvoke.net. , WM_KEYUP c, WM_KEYDOWN (0). KEYDOWN KEYUP , , Control , , KEYDOWN "p", IE. 0 KEYDOWN KEYUP. Backspace, , KEYDOWN, 0, Control-Backspace, , IE, , c = vbBack, KEYDOWN .

, 1 500 . , WebBrowser.

- AxWebBrowser. ActiveX, -, Control-P, , .Net.

+1

AJAX . InvokeMember ("click").

sendkeys script , - ( , ). , iMacros: http://www.iopus.com/iMacros/component.htm

0

Source: https://habr.com/ru/post/1709178/


All Articles