Reputation: 31
I would like to use...
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
With appropriate code to check a checkbox on a webpage
The HTML Code on the rendered page is...
<form class="form-inline" style="float:right">
<div class="checkbox">
<label style="padding-top: 1px">
<input data-bind="checked: orderBook.showAll" style="top:2px"
type="checkbox" /> Show All
</label>
</div>
</form>
I can't use getElementsByID()
as I don't think it has one.
Any suggestions?
Upvotes: 3
Views: 61
Reputation: 10139
While your checkbox does not have an ID, it does have a Class. Without seeing more of the HTML code I cannot be entirely sure, but the following code should allow you to set your checkbox to a variable:
Option Explicit
Sub test
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
' Navigate to desired web page
' Code to ensure page is fully loaded
Dim cBox As Object
Set cBox = IE.document.getElementsByClassName("checkbox")(0)
End Sub
Then you can use cBox
how you need to (possibly like cBox.Click
or another method). Notice that I appended (0) to the end of that statement? That means you are assigning the first instance of that class to the variable. If this checkbox is the only object with the class name of checkbox, then this won't be an issue, but you may have to change this number if it's not.
Upvotes: 1