Sign in to follow this  
Followers 0
CE101

Accessing Checkboxes on a Webpage

6 posts in this topic

This is a followup to an earlier topic (same subject line) from June24.

http://www.autoitscript.com/forum/index.php?showtopic=116323&pid=811702&st=0&#entry811702

Here's the preamble to my earlier posting...

As I explained earlier, I am writing a script that automates the clicking of checkboxes on a webpage.

We subscribe to an online list broker that allows us to compile and download lists of companies. First you enter the desired criteria (geography, industry, size, etc) and then you are presented with a list of companies meeting those criteria. Then you select the desired companies by clicking the appropriate check boxes. The system displays 10 companies per page, so if the list contains 75 companies there will be 8 pages. Unfortunately there's no "choose all" function. You have to click each company individually.

The challenge is figuring out the precise location of the checkboxes so that they can be checked. Getting the location of the top checkbox is no problem using Au3Info.exe. And from there it should be a no brainer to determine the location of the subsequent checkboxes. Usually there's 43 pixels between each checkbox, however if the line is wrapped (example a long company name) 43 pixels is no longer the correct number. And since I cannot determine if the line is wrapped it's impossible to figure out where is the next checkbox.

I know that AutoIT's standard IE library (ie.au3) contains the desired functionality. However this particular webpage does not work well with Internet Explorer so I am using FireFox. Obviously AutoIT's IE functions won't work here.

Two people came forward with some ideas.

PsaltyDS offered the following advice....

IE has a COM interface that exposes the DOM (document object model) and application automation where AutoIt can use it. Firefox doesn't. There is an FF.au3 UDF for Firefox, but using it requires you to fist install a Firefox plugin called MoxRepl, which exposes FF internals to external automation, so scripts written for it will not work unless that plugin is installed first..... P.S. Finding elements by pixel coordinates is going to be a highly unreliable, looserly proposition.

871 offered the following advice....

there is an addon called IE Tab Plus which enables you to use the embedded IE engine within tabs of Firefox. Useful when you want your script to work with both IE and FF without creating 2 different versions of script for each browser.

Regarding FF.au3 ....

After visiting the FF forum on AutoIT, I get the impression the the FF udf is still under development and keeps on changing. Also there a no examples similar to those in the regular AutoIT help file. I would imagine that the only way one would know how to use these functions is by delving into the code to see what they do. I'm not a programmer and only began using AutoIT a few weeks ago. Without the AutoIT help file I'd be lost. So I don't think there's much have hope for me using the FF udf in its current state. Unless someone could can give me some tangible examples.

Regarding IE Tab Plus ....

I visited the IE-Tab site (www.ietab.net) and downloaded the current version. When I tried running it I got the following message.... " The current version of IE Tab Plus can only work on Microsoft Windows XP SP2 or later. However, you can still use the former version Coral IE Tab v1.85, which can be downloaded from: Mozilla Addons Site "

Unfortunately I am using Win2000. Why I haven't upgraded to a newer OS, is a whole long story which I won’t trouble you with.

Anyways I searched around for the older version (v1.85) but could not find it. So I posted a message on the forum asking for the download page, but there has been no response.

Continuing my quest to automate the clicking of these checkboxes, another idea occurred to me, however I still need some advice on how it can be done...

First of all, here are some givens...

(1) The horizontal position of the checkboxes is known. That never changes. It's the vertical positions that change. And this is problematic for me as as they can vary depending on word wrap.

(2) Checkboxes are vertically spaced from each other by approx 30 to 40 pixels, depending on whether there is word wrap.

(2) There are some fixed visual landmarks on the page which can guide us. For example, the first checkbox appears about 50 pixels below the following text: "Clear All"

So here's my idea.... Instead of trying to pinpoint the checkboxes, let's plaster the screen with clicks in the following way...

(1) Send the following keystrokes to Firefox

....... Send ("{ALTDOWN}E{ALTUP}F") ; AltE F = Edit/Find

....... Send ("Clear All")

(2) Get the current mouse position -- it should be positioned at the text "Clear All"

(3) Position the mouse 50 pixels below the text and send a LeftClick .

(4) Position the mouse 10 pixels further down the page and send a LeftClick

(5) Continue step 4 another 500 times (that should take us to the bottom of the page).

In this scenario we will end up clicking all the checkboxes, although the vast majority of the clicks will be hitting dead space.

AND NOW MY QUESTION:

Regarding step# 2 ..... Does AutoIT have a generic (non IE) function that retrieves the mouse position relative to a Control (in this case the FF browser page)?

Any suggestions would be greatly appreciated. Sample code would be even better.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

http://findicons.com/ietab?v=1.85.20100407

Edit:

MouseGetPos() can return the co-ordinates reletive to the client area of a window, when setting the MouseCoordMode appropriately.

Also FF.au3 functions (as far as I can tell) emulate those of IE au3 so figuring them out should be quicker than piss balling about with pixels on a webpage, and " plastering the screen with clicks".

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Hi JohnOne - thank you for reminding me about MouseGetPos. Actually I came across this udf two weeks while reading the Help files, but for some reason it escaped my memory when it was needed.

Share this post


Link to post
Share on other sites

Hi JohnOne - thank you for reminding me about MouseGetPos. Actually I came across this udf two weeks while reading the Help files, but for some reason it escaped my memory when it was needed.

it looks like you've got a solution i guess, but couldn't you just use tabs and spaces to accomplish the same goal a lot easier?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Hi cameronsdad:

Thank you for the suggestion.

On this particular webpage using tabs would be very difficult. Besides the checkboxes, there are a lot of other controls and hyperlinks that you would have to bypass with the tab key. For example: PreviousPage, NextPage, FirstPage, LastPage, GotoPage#. However not all of these controls are available on all instances of the page. For example the first page doesn’t have the PreviousPage button and the last page doesn’t have the NextPage button. And furthermore if it's page 1 of 1 or it's the last page you don't know how many records are being displayed or the number of checkboxes. Without first finding some familiar landmarks you'd be "tabbing in the dark".

Share this post


Link to post
Share on other sites

Hi cameronsdad:

Thank you for the suggestion.

On this particular webpage using tabs would be very difficult. Besides the checkboxes, there are a lot of other controls and hyperlinks that you would have to bypass with the tab key. For example: PreviousPage, NextPage, FirstPage, LastPage, GotoPage#. However not all of these controls are available on all instances of the page. For example the first page doesn’t have the PreviousPage button and the last page doesn’t have the NextPage button. And furthermore if it's page 1 of 1 or it's the last page you don't know how many records are being displayed or the number of checkboxes. Without first finding some familiar landmarks you'd be "tabbing in the dark".

But you should know when you're on the first page, and you could even grab the page numbers etc from on the page... tabbing in the dark using controlsend would be worse than randomly clicking?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0