Solved

click on checkbox in webpage using vb

Posted on 2014-02-07
22
355 Views
Last Modified: 2014-02-24
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.pdf">        
        <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</span>
        </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.pdf">        
        <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</span>
        </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.pdf">        
        <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</span>
        </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.pdf">        
        <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</span>
        </div>
        <div class="lastUnit">
            2/4/2014 1:20:39 PM
        </div>
    </li>
0
Comment
Question by:rjef
  • 10
  • 9
  • 3
22 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39843673
You need to give the checkbox an ID.
Do you want to set it checked when the page loads (add attribute "checked='checked'") or based on some kind of user action (onclick="")?
0
 
LVL 33

Expert Comment

by:Norie
ID: 39844553
Which checkbox do you want to click?

Also, what code do you have so far?
0
 

Author Comment

by:rjef
ID: 39845451
lets say i want to click on this check box
<li class="line" rel="Scan_2014_02_04_12_53_55_486.pdf">        
        <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</span>
        </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
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39846192
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
0
 

Author Comment

by:rjef
ID: 39846320
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.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39846367
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(".line>div>input[type='checkbox']").checked="checked";
0
 

Author Comment

by:rjef
ID: 39847144
so how do put this in my vb app and how would i check the second checkbox instead of the 1st.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39848395
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.
0
 

Author Comment

by:rjef
ID: 39850093
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.
0
 
LVL 33

Expert Comment

by:Norie
ID: 39850391
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.
0
 

Author Comment

by:rjef
ID: 39850424
imnorie please provide an example
0
 
LVL 33

Expert Comment

by:Norie
ID: 39851812
Can you provide the URL of the site?
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39852423
Ah good catch. I missed that.
This week give the third element (zero based array)

document.getElementById("cabinetDocuments").children[2].firstChild.firstChild.firstChild.checked="checked"
0
 

Author Comment

by:rjef
ID: 39853122
imnorie,
the site is behind a firewall .  if you email me at rjef041364@yahoo.com i can send you all of
it.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39854444
Did you see the code in my last comment?
0
 

Author Comment

by:rjef
ID: 39854693
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?
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39854746
No, there are only ever going to be 3 firstchilds as they are referring to the elements like this:

document.getElementById("cabinetDocuments") <==== 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.pdf">        
.firstChild      <===== This is the <div class="unit">
.firstChild.checked="checked"    <===== this is the checkbox <input type="checkbox" />
0
 

Author Comment

by:rjef
ID: 39856088
it says object required.

ie.document.getElementById("cabinetDocuments").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">
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39869769
Not sure why firstChild doesn't work, however this does:

var n=3; // 4th checkbox
document.getElementById("cabinetDocuments").children[n].children[0].children[0].checked="checked";
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39869770
http://jsbin.com/cun/2/edit to see it in action
0
 

Author Comment

by:rjef
ID: 39870089
error
see attachment
Presentation1.jpg
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39871762
Ah ok, change uses round brackets for arrays so change all the square [ ] brackets to round ( )
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel file not created as expected 7 72
Receipt Printer for web based app 3 69
FireFox Add-on Plugins 3 26
Copy a range from 1..n excel sheets to one destination sheet 2 36
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Several part series to implement Internet Explorer 11 Enterprise Mode
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question