Jump to content

Button-Click by "Value"


 Share

Recommended Posts

Hey guys,

I have a problem and I cant figure it out... So, I want wo click a Button, but all I get in the Source is:

<button name="bauwerk_typ_id" type="submit" value="0" onclick="submit_summoned_building(0);return false;">

It is possible to "click" it with IE.au3?^^

Regards,

Acanis

Link to comment
Share on other sites

Something like this:

$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.value) = "your value" Then
        _IEAction($oButton, "click")
        ExitLoop
    EndIf
Next

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

Thank you^^ Looks good and "easy", but its not working...

I also tried ->

$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
     If $oButton.getAttribute('value',0) <> "" Then
        If $oButton.getAttribute('value',0) = "17" Then
        _IEAction($oButton, "click")
        ExitLoop
    EndIf
        EndIf
Next

Please help me :)

Regards,

Acanis

*edit*

I tried this, and the source, he found, is a different... -.-

#include <ie.au3>
#include <string.au3>

$ie=_IECreate("http://troll.xhodon.de/xhodon/summon.php")
$body = StringLower( _IEBodyReadHTML($ie) )

MsgBox(0,"TEst",$body)
Edited by Acanis
Link to comment
Share on other sites

You said my code didn't work... it obviously needed to be modified to fit your page... show what you used.

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

The Func is ->

Func _test()
_IENavigate($oIE, "http://troll.xhodon.de/xhodon/summon.php")
$oButtons = _IETagnameGetCollection($oIE, "button")
For $oButton in $oButtons
    If String($oButton.value) = "17" Then
        _IEAction($oButton, "click")
        ExitLoop
    EndIf
Next
EndFunc

The part before is just "login"... Then he has to go to the "summon"-page and this is like a "test", that I know, how I can work with this, to summon buildings... :)

What do I have to change? Looks good...

But if I try to do JUST the $oButtons = _IETagnameGetCollection($oIE, "button") and put the result in a MSGBox... -> NOTHING... -.-

Regards,

Acanis

Edited by Acanis
Link to comment
Share on other sites

Your code has no MSGBOX, but note that $oButtons is an object variable, so displaying it will not give you anything useful.

After the call to _IETagNameGetCollection, check the value of @extended and it will tell you how many button objects were found. Also, be sure to look at the SciTe console for diagnostic messages. If @extended is 0, check the page source to insure there are button's and make sure you don't need to drill into frames or iframes.

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

Your code has no MSGBOX, but note that $oButtons is an object variable, so displaying it will not give you anything useful.

After the call to _IETagNameGetCollection, check the value of @extended and it will tell you how many button objects were found. Also, be sure to look at the SciTe console for diagnostic messages. If @extended is 0, check the page source to insure there are button's and make sure you don't need to drill into frames or iframes.

Dale

Ya, the MSGBOX was just a test, its not in the script...

*hm*...

@extended gave me "11"... Thats good xD...! (11 buildings...)

In Scite I get no warnings... :)

Edited by Acanis
Link to comment
Share on other sites

You may not be clicking on the right button (perhaps look at outerHTML with _IEPropertyGet), or more than a .click event is required - you need to tare apart the HTML and Javascript to know what is needed. You may also want to look at the second example for _IEAction for an alternate method of activating the button.

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

You may not be clicking on the right button (perhaps look at outerHTML with _IEPropertyGet), or more than a .click event is required - you need to tare apart the HTML and Javascript to know what is needed. You may also want to look at the second example for _IEAction for an alternate method of activating the button.

Dale

<div class="building_build_item building_build">       
        <button name="bauwerk_typ_id" type="submit" value="11" 
                    onclick="submit_summoned_building(11); return false;"  >
        <div class="building_palasthof big_pic"></div>
                 
        <div class="building_text">
        <div class="nameContainer">
            <span class="name"><strong>Palasthof</strong></span>            
                            <span class="level">
                auf Stufe 2
                            </span>
        </div>
                                            <div class="costs_line
                    ">
                    <img style="height:14px;" alt="Essenzen" title="Essenzen" src="http://troll.xhodon.de/xhodon/gfx//icons/essenz.png"/> 
                    <span>2.936</span>
                </div> 
                                <div class="costs_line
                    ">
                    <img style="height:14px;" alt="Kristallsplitter" title="Kristallsplitter" src="http://troll.xhodon.de/xhodon/gfx//icons/kristall.png"/> 
                    <span>3.584</span>
                </div> 
                                <div class="costs_line
                    ">
                    <img style="height:14px;" alt="Kraftsteine" title="Kraftsteine" src="http://troll.xhodon.de/xhodon/gfx//icons/kraftstein.png"/> 
                    <span>2.604</span>
                </div> 
                                <div class="costs_line
                    ">
                    <img style="height:14px;" alt="Goldharz" title="Goldharz" src="http://troll.xhodon.de/xhodon/gfx//icons/goldharz.png"/> 
                    <span>1.160</span>
                </div> 
                                <div class="costs_line">                            
                    <img name="icon_mana" style="height:14px;" alt="Mana" title="Mana" src="http://troll.xhodon.de/xhodon/gfx//icons/mana.png"/>
                    <span  class="build_time" name="build_time" id="11">13.10.2009 14:30:00</span>                      
                </div>                                  
            
                        
                    </div>
                    
        </button>
        </div>

This is one "button"... Ill try the second method for activating...

IF he really find the "11", its the right button...

*edit*

Not working with "focus"... -.-

He cant find the value, I think...

I changed it to ->

If String($oButton.value) = "17" Then
        MsgBox(0, "hi", $oButton)
        _IEAction($oButton, "click")

SO, with a MSGBOX... And... NOTHING :)

Edited by Acanis
Link to comment
Share on other sites

Yesterday I tried it also with:

_IENavigate($oIE, 'javascript:submit_summoned_building(17); return false;', 0)

Now I have 2 more of building "17"... But no ressources to test... xD Could it be, that this is working???... Or was it something different?

*edit*

With "javascript:submit_summoned_building(10)" I can "build" buildings... If I send it to the IE... But then I come to a empty page with just "FALSE"...

I dont want to "go" back then... What can I do?... The whole Javascript was "onclick="submit_summoned_building(0);return false;" But its not working with "return false"... -.-

Edited by Acanis
Link to comment
Share on other sites

It all depends on what is in the Javascript function submit_summoned_building. When you are lucky it only relies on the parameter passed to complete its task, but it can do a lot more... it can rely on the "this" object, that is the object variable on the object that called the function with the onclick event... it can rely on the event (evt) object and can look at mouse coordinates, mouse button pressed, it can rely on state variables set by other events on other objects as well (like an onmouseover event from a containing div or table cell for example) etc, etc

If firing the onclick event with _IEAction is not enough, you need to dig into all of the other logic and you MUST do something to insure that you are clicking on the correct element (see my suggestions above).

Your descriptions are vague and incomplete, so I really can provide little other guidance.

Dale

P.S. based on your MsgBox(0, "hi", $oButton) above, you have still not grasped that examining the content of an object variable directly does you not good. It is a reference to a structure that you can vector into with object-oriented syntax for properties, methods and events.

Edited by DaleHohm

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