Jump to content

Problem with checkboxes in IE


 Share

Recommended Posts

Good morning,

it is my very first time I work with AutoIt.

My first Script is about to download some files from a homepage.

I found the following function to set checkboxes on the internet:

Func _IEX_CheckboxSetStatebyName($objekt, $name, $state = True)
    $oObjekt = _IEGetObjByName($objekt, $name)
    If not (($state = $oObjekt.checked) = True) Then
        _IEAction($oObjekt, "click")
    EndIf
EndFunc

This worked with my first checkboxes, but I got a problem using this on another part of this page. Because I have to login on this page with a company-internal user and password I can not give you access to this. But I hope the following HTML-Code will help:

<form action="/report/run">
<h3>Fields to Display</h3>
<table width="100%" class="layout">
<tr>
<td valign="top">
<b>Product Details</b><br/>
<input type="checkbox" name="d_product" id="d_product" checked="checked"/>Product name<br/>
<input type="checkbox" name="d_company" id="d_company" checked="checked"/>Company<br/>
<input type="checkbox" name="d_lc" id="d_lc" />Legacy Company<input type="checkbox" name="d_lccoc" id="d_lccoc"/>Change of Control Date<br/>
<input type="checkbox" name="d_country" id="d_country" checked="checked"/>Country<br/>
<input type="checkbox" name="d_legalcat" id="d_legalcat"/>Legal category
<input type="checkbox" name="d_legalcatchanged" id="d_legalcatchanged"/>Date Changed<br/>
<input type="checkbox" name="d_fad" id="d_fad"/>First Approval Date<br/>
<input type="checkbox" name="d_marketauth" id="d_marketauth"/>Marketing Authorisation<br/>
[b]<input type="checkbox" name="d_marketed" id="d_marketed"/>Marketed<br/>[/b] ----------------------
<input type="checkbox" name="d_withdrawn" id="d_withdrawn"/>Product Withdrawn<br/>
<input type="checkbox" name="d_regcode" id="d_regcode"/>Regulatory Code<br/>
</td>
</tr>
 
<tr>
<td valign="top"><b>Active/Antigen</b><br/>
<input type="checkbox" name="d_aaname" id="d_aaname"/>Active/Antigen name<br/>
<input type="checkbox" name="d_aastate" id="d_aastate"/>Antigen state<br/>
<input type="checkbox" name="d_aacat" id="d_aacat"/>Active/Antigen category<br/>
<input type="checkbox" name="d_pres" id="d_pres"/>Presentation<br/>
</td>
<td valign="top"><b>Indications</b><br/>
<input type="checkbox" name="d_species" id="d_species"/>Species
<input type="checkbox" name="d_spapproval" id="d_spapproval"/>New Approval Date<br/>
<input type="checkbox" name="d_route" id="d_route"/>Administration route<br/>
<input type="checkbox" name="d_subroute" id="d_subroute"/>Administration sub-route<br/>
<input type="checkbox" name="d_ud" id="d_ud"/>Use-Disease
<input type="checkbox" name="d_udapproval" id="d_udapproval"/>New Approval Date<br/>
<input type="checkbox" name="d_udcat" id="d_udcat"/>Use-Disease category<br/>
</td>
</tr>
</table>
<h3>Report Options</h3>
<table class="layout">
<tr>
<td><input type="submit" name="r_full" value="Full Report" id="r_full"/></td>
<td>Display all information on the matching products.</td>
</tr>
<tr>
<td><input type="submit" name="r_restrict" value="Restricted Report" id="r_restrict"/></td>
<td>Display only specified criteria from product search.</td>
</tr>
 
</table>
</form>

I tried to set the bold checkbox as 'checked' with this AutoIt-Code:

_IEX_CheckboxSetStatebyName($oIE, "d_marketed", True)

which worked for other checkboxes.

On these checkboxes I get the error: "Error: Variable must be of type "Object"".

The mistake must be on line :

If not (($state = $oObjekt.checked) = True) Then

But though I am not familiar with AutoIt I do not have any idea about a solution.

I would be appreciated for any help.

Greets,

Michael :mellow:

Edited by Mich90
Link to comment
Share on other sites

I actually encounterd a similar problem but in an installation of a program but my solution to that problem might not be able to implement on a website though :S

I located the windows X(WinX)and Y(winY) and took the X(editX) and Y(editY) from the edit box made a calculation to locate the 0,0 coordinate of the edit field and made the calculation with thouse variables to reach to the checkboxes in the editbox.

$editZeroX = $winX + $editX
$editZeroY = $winY + $editY

$checkboxX = $editZeroX + int (freebased)
$checkboxY = $editZeroY + int (freebased)

MouseClick ("left" ,$checkboxX  ,$checkboxY ,1)

I do not recommend this method if there is any easier way to do it as it is dependent on the resolution :S

Link to comment
Share on other sites

I actually encounterd a similar problem but in an installation of a program but my solution to that problem might not be able to implement on a website though :S

I located the windows X(WinX)and Y(winY) and took the X(editX) and Y(editY) from the edit box made a calculation to locate the 0,0 coordinate of the edit field and made the calculation with thouse variables to reach to the checkboxes in the editbox.

$editZeroX = $winX + $editX
$editZeroY = $winY + $editY

$checkboxX = $editZeroX + int (freebased)
$checkboxY = $editZeroY + int (freebased)

MouseClick ("left" ,$checkboxX  ,$checkboxY ,1)

I do not recommend this method if there is any easier way to do it as it is dependent on the resolution :S

Did you try ControlCommand and "check" option ? Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

I got it!

The only problem was that the page was not finished with loading I think. A

Sleep(1000)

solved all the problems.

But I do not know how this can happen because I thought that

_IELoadWait($oIE)

which I also did before I wanted to click on the checkboxes, would wait till end of loading process....

Whatever...I was wrong with that.

Edited by Mich90
Link to comment
Share on other sites

Pages that use techniques such as AJAX can technically finish loading the document, but can continue to make updates to the page asynchronously. A sleep may get you past this, but depending on load times it is not a guarantee.

You can also use _IELoadWait on other page elements instead of just $oIE (like a form element, for example) or you can check for the existance of an element that is created dynamically before continuing.

In your case, something like:

While Not IsObj(_IEGetObjByName($oIE, "d_marketed")
    Sleep(200)
WEnd

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...