Jump to content

IE.au3 Dropdown menu and submit


Go to solution Solved by jdelaney,

Recommended Posts

Okay so I'm still pretty new with Autoit. I recently decided to mess around with the IE.au3 UDF.

I'm stumped. Currently I've been able to create a new browser and navigate to a webpage. I also figured out how to attach my script to an existing IE browser.

What I'm currently stumped on is I can't figure out how to select a dropdown menu.

On a website I'm on there is a dropdown menu. You click it and all the options pop down (typical menu). I want to be able to select a certain item from that dropdown menu. Then click the submit button.

Any help is appreciated. (And yes, I used google but I couldn't find exactly what I was looking for. Or if I did it was too confusing for me to understand.)

Edited by BitOfHope
Link to comment
Share on other sites

could you post a link to the site containing that dropdown menu ?

I'd rather not post my banks website =/ I'm using it as a test site to help learn this UDF.

Is there a way to help me without linking the site directly? I could try to find another site with a dropdown menu if it's needed.

Edit: Here we go. The dropdown menu on this calorie calculator page. How would I select different options in that dropdown menu and then click the [CALCULATE] button? http://www.freedieting.com/tools/calorie_calculator.htm

Edited by BitOfHope
Link to comment
Share on other sites

  • Solution

basic example...the calculate will fail, since I'm not setting all required values...but this is just for demonstration of select and submit:

#include <ie.au3>

$oIE = _IECreate("http://www.freedieting.com/tools/calorie_calculator.htm",True)
$oActivitySelect = _IEGetObjById($oIE, "activity")
_IEFormElementOptionSelect($oActivitySelect,"1.2") ; Select's "Little/no exercise"

$oCalculate = _IEGetObjById($oIE, "Button1") ; click calculate
_IEAction($oCalculate, "click")
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

basic example...the calculate will fail, since I'm not setting all required values...but this is just for demonstration of select and submit:

#include <ie.au3>

$oIE = _IECreate("http://www.freedieting.com/tools/calorie_calculator.htm",True)
$oActivitySelect = _IEGetObjById($oIE, "activity")
_IEFormElementOptionSelect($oActivitySelect,"1.2") ; Select's "Little/no exercise"

$oCalculate = _IEGetObjById($oIE, "Button1") ; click calculate
_IEAction($oCalculate, "click")

Wow, this works! Would you mind adding in notes breaking down what every little thing does? If not that's fine, I can work it out on my own. Thank you either way!

Link to comment
Share on other sites

Open the webpage, and press F12...there is a tool to point at the IE object, which will return the source...example from the 'Select'...notice the @id = activity...so, that's how I grabbed the object. 

As for the functions I used, click on them to see the help file, and an explanation.

<select name="activity" id="activity">
              <option value="1.0">Basal Metabolic Rate</option>
              <option value="1.2">Little/no exercise</option>
              <option selected="true" value="1.375">3 times/week</option>
              <option value="1.4187">4 times/week</option>
              <option value="1.4625">5 times/week</option>
              <option value="1.550">5 times/week (intense)</option>
              <option value="1.6375">Every day</option>
              <option value="1.725">Every day (intense) or twice daily</option>
              <option value="1.9">Daily exercise + physical job</option>
</select>
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

Open the webpage, and press F12...there is a tool to point at the IE object, which will return the source...example from the 'Select'...notice the @id = activity...so, that's how I grabbed the object. 

As for the functions I used, click on them to see the help file, and an explanation.

<select name="activity" id="activity">
              <option value="1.0">Basal Metabolic Rate</option>
              <option value="1.2">Little/no exercise</option>
              <option selected="true" value="1.375">3 times/week</option>
              <option value="1.4187">4 times/week</option>
              <option value="1.4625">5 times/week</option>
              <option value="1.550">5 times/week (intense)</option>
              <option value="1.6375">Every day</option>
              <option value="1.725">Every day (intense) or twice daily</option>
              <option value="1.9">Daily exercise + physical job</option>
</select>

This is fantastic.

But when I try this on another site it doesn't want to do... anything. At all. I might be grabbing the wrong ID but I'm pretty much out of things to try. Would there be some reason I wouldn't be able to manipulate it?

Link to comment
Share on other sites

Nope, you can add debugging, or post the HTML source, like I did above, and someone (or myself) will tell you what's wrong...post your code too (you can strip out your actual url).

debugging example:

#include <ie.au3>

$oIE = _IECreate("http://www.freedieting.com/tools/calorie_calculator.htm",True)
$oActivitySelect = _IEGetObjById($oIE, "activity")
If Not IsObj($oActivitySelect) Then
    MsgBox(1,1,"Unable to find the 'Select'.")
    Exit
EndIf
_IEFormElementOptionSelect($oActivitySelect,"1.2") ; Select's "Little/no exercise"

$oCalculate = _IEGetObjById($oIE, "Button1") ; click calculate
_IEAction($oCalculate, "click")
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

 

Nope, you can add debugging, or post the HTML source, like I did above, and someone (or myself) will tell you what's wrong...post your code too (you can strip out your actual url).

debugging example:

#include <ie.au3>

$oIE = _IECreate("http://www.freedieting.com/tools/calorie_calculator.htm",True)
$oActivitySelect = _IEGetObjById($oIE, "activity")
If Not IsObj($oActivitySelect) Then
    MsgBox(1,1,"Unable to find the 'Select'.")
    Exit
EndIf
_IEFormElementOptionSelect($oActivitySelect,"1.2") ; Select's "Little/no exercise"

$oCalculate = _IEGetObjById($oIE, "Button1") ; click calculate
_IEAction($oCalculate, "click")

 

Okay, here is the HTML source(I think? It's a little confusing):

<form id="menuForm" class="autoInput" action="?id=18" method="post">
                                                                        <select name="print">
                                                                                                <option value="option1">Selection1(Default)</option>
                                                                    <option value="option2">Selection 2</option>
                                                                    <option value="option3">Selection 3</option>
                                                                    <option value="option4">Selection 4</option>
                                                                    <option value="option5">Selection 5</option>
                                                                    <option value="option6">Selection 6</option>
                                                                                    </select>
                                                                    <input class="input_submit_btn" style="width:110px; line-height:15px;margin:10px;" type="submit" name="Submit" value="Submit">
          </form>

Here's my current script:

#RequireAdmin
#include <IE.au3>

$oIE = _IECreate("myurlhere", True)
$oActivitySelect = _IEGetObjById($oIE, "menuForm")
_IEFormElementOptionSelect($oActivitySelect, "option2")
$oCalculate = _IEGetObjById($oIE, "submit")
_IEAction($oCalculate, "click")

When I run the script it selects my web browser and then just sits there.

Edit: To add on to this when I use your debug script it gives me the popup if I enter anything other than "menuForm"

Edited by BitOfHope
Link to comment
Share on other sites

Close...you want to grab the 'select', not the 'form'...notice there is no id, but there is a name, so use this one instead:

_IEGetObjByName

Your name is "print"

<select name="print">

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Close...you want to grab the 'select', not the 'form'...notice there is no id, but there is a name, so use this one instead:

_IEGetObjByName

Your name is "print"

<select name="print">

I've tried using print.

#RequireAdmin 
#include <IE.au3> $oIE = _IECreate("myurlhere", True) 
$oActivitySelect = _IEGetObjById($oIE, "print") 
_IEFormElementOptionSelect($oActivitySelect, "option2") 
$oCalculate = _IEGetObjById($oIE, "submit") 
_IEAction($oCalculate, "click")

(Right?)

It doesn't work =/ I used the debugging script you posted and the box pops up and says Unable to find the 'Select'.

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...