Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webbrowser Automation and image input control 1

Status
Not open for further replies.

mdrack

Programmer
Joined
Jan 20, 2004
Messages
9
Location
GB
I'm converting an application from VB6 to VB.NET and all gets converted fine apart from a section where I want to automate an image being clicked on.

The application uses the webbrowser control to signon to a web site, navigate to a certain page, click some radio and checkbox controls then click on a image input control to finish. This just crashes with 'Object variable or With block variable not set' in VB.NET

The VB6 code once you are on the right page is like this;

Dim frm As HTMLFormElement
Dim doc As HTMLDocument
Dim tlist As Object

Set doc = WebBrowser1.Document

Set frm = doc.Forms(0)

' Select XML format
Set tlist = frm.namedItem("downloadType")
tlist.Item(1).Checked = True

Set tlist = frm.namedItem("downloadIds")
' Call a subroutine to tick all the relevant checkboxes
tick_new tlist, WebBrowser1.Document.body.innerText

' Click on the download button
WebBrowser1.Document.All("downloadChecked").Click

And that works.

The HTML is like this;

<form name="grbReportDownloadForm" method="post" action="/online/newbacs/ocs/download/sort.do" class="grb" id="list">
<fieldset class="tertiary_background">
....


<input type="image" name="downloadAll" src="/gr_online/images/download_all.gif" />
<input type="image" name="downloadChecked" src="/gr_online/images/download.gif" />
</div>
</td>
</tr>
</table>
</fieldset>
</form>

The VB.NET code is like this;

Dim frm As MSHTML.HTMLFormElement
Dim doc As MSHTML.HTMLDocument
Dim tlist As Object

doc = WebBrowser1.Document.DomDocument

frm = doc.Forms.item(0)

' Select XML format
tlist = frm.namedItem("downloadType")
'UPGRADE_WARNING: Couldn't resolve default property of object tlist.Item. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tlist.Item(1).Checked = True

tlist = frm.namedItem("downloadIds")
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.body. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
tick_new(tlist, WebBrowser1.Document.DomDocument.body.innerText)

' Click on the download button
'UPGRADE_WARNING: Couldn't resolve default property of object WebBrowser1.Document.All. Click for more: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
WebBrowser1.Document.DomDocument.All("downloadChecked").Click()

So anyone know what's wrong or just how you click on an image input control?

Thanks in advance.
 
Try as follows for the click of "downloadchecked", similar for any others:

Dim hElement As HtmlElement = Nothing

hElement = Webbrowser1.Document.GetElementById("downloadChecked")
hElement.InvokeMember("click")


Let me know how it works.

~CIAO
 
Thanks for replying, sorry for the delay but I didn't get the email saying there was a reply.

I've tried that and I get 'Object reference not set to an instance of an object' when it does the InvokeMember. It's like the element does not exist on the page. Is there a way to view which elements are in the webbrowser object?

Thanks again
 
What is tList? Prolly doesn't like Object

Did you check out the link? They're pretty self-explanatory

MSDN Help is also a good source of info.

-David
2006 & 2007 Microsoft Most Valuable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
dglienna: tlist is the object I use to hold the array of named items. That part works, I only get the error on the final click. When I've commented out that click and let the program flow return to the main form, I can see on the webbrowser control on my form that the named items ("downloadType") and ("downloadIds") have been ticked.

The link is just to the standard warning that VB.NET doesn't like default properties.

MSDN is good but on webbrowser all it really has is how to use it to write your own browser where a user clicks on the links. It has very little on how to automate visiting a web page. Unless you know different?

arznrchrd: Yes. Well I believe so. I've navigated to this page and the webbrowser object has all the details of the page loaded, apart from this image input control.
 
Are you getting an id returned from
hElement = Webbrowser1.Document.GetElementById("downloadChecked")
?

Try:
Dim hElement As HtmlElement = Nothing

hElement = Webbrowser1.Document.GetElementById("downloadChecked")
hElement.InvokeMember("submit")
 
Still get 'Object reference not set to an instance of an object' using submit.

hElement is equal to Nothing after the GetElementById line so it's like it believes the element is not on the page. But it is there!

Thank you for your response
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top