rjef
asked on
click on checkbox in webpage using vb
Any idea how to click on one of the check boxes in the below web page html
<ol id="cabinetDocuments">
<li class="line" rel="Scan_2014_02_04_12_55 _04_036.pd f">
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_ 55_04_036. pdf">Scan_ 2014_02_04 _12_55_04_ 036.pdf</s pan>
</div>
<div class="lastUnit">
2/4/2014 1:22:04 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53 _55_486.pd f">
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_ 53_55_486. pdf">Scan_ 2014_02_04 _12_53_55_ 486.pdf</s pan>
</div>
<div class="lastUnit">
2/4/2014 1:20:58 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53 _45_246.pd f">
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_ 53_45_246. pdf">Scan_ 2014_02_04 _12_53_45_ 246.pdf</s pan>
</div>
<div class="lastUnit">
2/4/2014 1:20:49 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53 _36_176.pd f">
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_ 53_36_176. pdf">Scan_ 2014_02_04 _12_53_36_ 176.pdf</s pan>
</div>
<div class="lastUnit">
2/4/2014 1:20:39 PM
</div>
</li>
<ol id="cabinetDocuments">
<li class="line" rel="Scan_2014_02_04_12_55
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_
</div>
<div class="lastUnit">
2/4/2014 1:22:04 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_
</div>
<div class="lastUnit">
2/4/2014 1:20:58 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_
</div>
<div class="lastUnit">
2/4/2014 1:20:49 PM
</div>
</li>
<li class="line" rel="Scan_2014_02_04_12_53
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_
</div>
<div class="lastUnit">
2/4/2014 1:20:39 PM
</div>
</li>
Which checkbox do you want to click?
Also, what code do you have so far?
Also, what code do you have so far?
ASKER
lets say i want to click on this check box
<li class="line" rel="Scan_2014_02_04_12_53 _55_486.pd f">
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_ 53_55_486. pdf">Scan_ 2014_02_04 _12_53_55_ 486.pdf</s pan>
</div>
<div class="lastUnit">
2/4/2014 1:20:58 PM
</div>
</li>
i am trying to use the ie.document.getElementById ( but i do now the id of the checkbox.
also i forgot to metion i am using vb6
<li class="line" rel="Scan_2014_02_04_12_53
<div class="unit">
<input type="checkbox" /><span class="doc-icon pdf" Title="Scan_2014_02_04_12_
</div>
<div class="lastUnit">
2/4/2014 1:20:58 PM
</div>
</li>
i am trying to use the ie.document.getElementById
also i forgot to metion i am using vb6
You can't use an ID if there isn't one. Add the ID as an attribute to the checkbox
<input type="checkbox" id="chk1" />
Then use your code with that ID
<input type="checkbox" id="chk1" />
Then use your code with that ID
ASKER
maybe i don't understand. I am trying to set the checkbox on a web site using the webbrowser control in vb6. I have no control of the source. you can email me at rjef041364@yahoo.com and i can send you the viewsource code for (the website ) you can review.
No, you do but I also understand a little more now. Given you don't have access to the site, you can't reference that checkbox using the getElementById function. What you're going to have to do is navigate the XML manually:
http://jsbin.com/pogah/1/edit?html,js,output
document.querySelector(".l ine>div>in put[type=' checkbox'] ").checked ="checked" ;
http://jsbin.com/pogah/1/edit?html,js,output
document.querySelector(".l
ASKER
so how do put this in my vb app and how would i check the second checkbox instead of the 1st.
You'd put it in the same place as you we going to with your getElementById.
To get the second you need to use a slightly different version of the function, querySelectorAll. This week return all elements matched rather than just the first.
To get the second you need to use a slightly different version of the function, querySelectorAll. This week return all elements matched rather than just the first.
ASKER
Rob,
Please email me at rjef041364@yahoo.com and i will send you the complete source could from the website. you do understand i cannot change code on the website. I want to manipulate from the client side.
Please email me at rjef041364@yahoo.com and i will send you the complete source could from the website. you do understand i cannot change code on the website. I want to manipulate from the client side.
You don't know the id of the checkbox but you do know the id of the ordered list the checkbox is in.
So you can grab the list and then loop through it to find the checkbox you want and set it to be checked.
So you can grab the list and then loop through it to find the checkbox you want and set it to be checked.
ASKER
imnorie please provide an example
Can you provide the URL of the site?
Ah good catch. I missed that.
This week give the third element (zero based array)
document.getElementById("c abinetDocu ments").ch ildren[2]. firstChild .firstChil d.firstChi ld.checked ="checked"
This week give the third element (zero based array)
document.getElementById("c
ASKER
imnorie,
the site is behind a firewall . if you email me at rjef041364@yahoo.com i can send you all of
it.
the site is behind a firewall . if you email me at rjef041364@yahoo.com i can send you all of
it.
Did you see the code in my last comment?
ASKER
yes not to sure how to use it though. my example only had 4 firstchilds but there could be many many more. would i just keep adding firstchild's?
No, there are only ever going to be 3 firstchilds as they are referring to the elements like this:
document.getElementById("c abinetDocu ments") <==== this is the OL ordered list
.children[2] <===== THIS IS THE KEY - you vary the number to get each child in the OL
.firstChild <===== This is the <li class="line" rel="Scan_2014_02_04_12_53 _55_486.pd f">
.firstChild <===== This is the <div class="unit">
.firstChild.checked="check ed" <===== this is the checkbox <input type="checkbox" />
document.getElementById("c
.children[2] <===== THIS IS THE KEY - you vary the number to get each child in the OL
.firstChild <===== This is the <li class="line" rel="Scan_2014_02_04_12_53
.firstChild <===== This is the <div class="unit">
.firstChild.checked="check
ASKER
it says object required.
ie.document.getElementById ("cabinetD ocuments") .children [2].firstChild.firstChild. firstChild .Checked = "checked"
also there is the in the source before the 'cabinetdocuments' if that matters.
</ul>
<div id="cabinetContentOuter">
<div id="cabinetContent">
<div id="cabinetResults">
ie.document.getElementById
also there is the in the source before the 'cabinetdocuments' if that matters.
</ul>
<div id="cabinetContentOuter">
<div id="cabinetContent">
<div id="cabinetResults">
Not sure why firstChild doesn't work, however this does:
var n=3; // 4th checkbox
document.getElementById("c abinetDocu ments").ch ildren[n]. children[0 ].children [0].checke d="checked ";
var n=3; // 4th checkbox
document.getElementById("c
http://jsbin.com/cun/2/edit to see it in action
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you want to set it checked when the page loads (add attribute "checked='checked'") or based on some kind of user action (onclick="")?