简体   繁体   中英

C# Can I Automate Drop Down Box in webbrowser control?

Hi this is my First time on here, learning C# at the moment and have hit a roadblock

I have a program that clicks through a webpage using the Webbrowser control, and I need it to pick options from a drop down box.

I have the HTML for the page, and so far I have been using element.InvokeMember for clicking buttons, and element.InnerText for inputing data.

Is there any way to manipulate a websites drop down box and pick values?

I have The ID for the Drop down box element and values for its options.

I aswered to same question , and quote myself. One can get handle to popup by WindowFromPoint function. Then you may use IAccessible interface to acsess elements of popup. Something like this:

const uint OBJID_NATIVEOM = 0;
Guid  IID_IAcce = new Guid("{618736e0-3c3d-11cf-810c-00aa00389b71}");

IntPtr inpt = WindowFromPoint( p);

object ptr1 = null;
int l;

l = AccessibleObjectFromWindow(inpt, OBJID_NATIVEOM,    IID_IAcce.ToByteArray(), ref ptr1);
var acc = ptr1 as IAccessible;

set the value of the option into the selected field

ie selected="ID"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM