Sign in to follow this  
Followers 0
fusion400

How to press button on webpage using IE udf?

9 posts in this topic

#1 ·  Posted (edited)

Hello i want to be able to click the button "Ny Spellista" using the IE udf.

How can it find the button and click on it i don't want to use au3 recorder or imagesearch? There must be a way to programatically click it with some command in the IE udf. That can detect the html code.

The code is below:

#include <IE.au3>
$o_IE = _IECreate("http://web.site.com")
sleep(2000)
Local $oInput, $oInputs = _IETagNameAllGetCollection($o_IE)
For $oInput In $oInputs
consolewrite($oInputs)
If $oInput == 'Ny spellista' Then
_IEAction($oInput, "click")
_IELoadWait($o_IE)
EndIf
Next

The HTML code for button is shown below:

<table style="margin-left: 18px;" border="0" width="85%">
         <tbody><tr>
             <td vAlign="top" width="30">
                
                 <span class="button"><a onclick="newplaylist_popup()">Ny spellista</a></span>
             </td>

I hope someone can help me with my problem.

Edited by fusion400

Share this post


Link to post
Share on other sites



the button is a link, so you can do the loop with _IELinkGetCollection, or you can use _IELinkClickByText (which seems more likely for you)

#include <IE.au3>
$o_IE = _IECreate("http://web.site.com")
_IELoadWait ( $o_I )
_IELinkClickByText ( $o_IE, 'Ny spellista' )

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.

Share this post


Link to post
Share on other sites

the button is a link, so you can do the loop with _IELinkGetCollection, or you can use _IELinkClickByText (which seems more likely for you)

#include <IE.au3>
$o_IE = _IECreate("http://web.site.com")
_IELoadWait ( $o_IE )
_IELinkClickByText ( $o_IE, 'Ny spellista' )

Thanks but it does not find any match.

I also used this code but it does not find any match either

#include <IE.au3>

$oIE = _IECreate("http://web.site.com")

Local $sMyString = "Ny spellista"
Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
Next

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

don't forget the load wait...added some message boxes to verify conditions are met:

#include <IE.au3>
$oIE = _IECreate("http://msn.com")
_IELoadWait($oIE)
Local $sMyString = "Maps"
$oLinks = _IELinkGetCollection($oIE)
MsgBox ( 1,1,$oLinks.length)
For $oLink In $oLinks
Local $sLinkText = _IEPropertyGet($oLink, "InnerText")

ConsoleWrite ( $sLinkText & @CRLF )
If StringInStr($sLinkText, $sMyString) Then
MsgBox ( 1,1,"found link")

     _IEAction($oLink, "focus")
     _IEAction($oLink, "click")
     ExitLoop
EndIf
Next

edit...i also like to focus prior to 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.

Share this post


Link to post
Share on other sites

don't forget the load wait...added some message boxes to verify conditions are met:

#include <IE.au3>
$oIE = _IECreate("http://msn.com")
_IELoadWait($oIE)
Local $sMyString = "Maps"
$oLinks = _IELinkGetCollection($oIE)
MsgBox ( 1,1,$oLinks.length)
For $oLink In $oLinks
Local $sLinkText = _IEPropertyGet($oLink, "InnerText")

ConsoleWrite ( $sLinkText & @CRLF )
If StringInStr($sLinkText, $sMyString) Then
MsgBox ( 1,1,"found link")

     _IEAction($oLink, "focus")
     _IEAction($oLink, "click")
     ExitLoop
EndIf
Next

edit...i also like to focus prior to click

I tried and there are a bunch of links listed if i do consolewrite($sLinkText)

but none that matches "Ny spellista" must be something in the website that keeps it from finding this button and click on it.

I have used another tool called Automate that can find it. But i don't like Automate because it can't create executable files.

It locates it by HTML tag A and then does a search for " Ny spellista " and finds it and clicks on it. Without a single line of code written.

The website is dynamically generated from PHP code.

Share this post


Link to post
Share on other sites

well, you can always attempt to use my signature, and find it via XPath...or, see if a wait after IELoad will allow the collection to include your link (if it's added after page loads)


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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

well, you can always attempt to use my signature, and find it via XPath...or, see if a wait after IELoad will allow the collection to include your link (if it's added after page loads)

Ok i will try XPath and see if it works an added sleep did not change anything.

I got confused with Xpath what would be the correct code to find "Ny spellista" using your udf?

Edited by fusion400

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

sample usage:

#include "C:AutomationEFLBrowser_generic.au3"
#include <Array.au3>
#include <IE.au3>
$oIE = _IECreate("http://msn.com")
_IELoadWait($oIE)
Local $sMyString = "Maps"
$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[contains(.," & $sMyString & ")]")
If IsArray($aObjects) Then
ConsoleWrite("Found matching elements=" & UBound($aObjects) & @CRLF)
_IEAction($aObjects[0], "focus")
_IEAction($aObjects[0], "click")
Else
ConsoleWrite("NO matching elements=" & @CRLF)
EndIf
Exit

or, you can do this

$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[.=" & $sMyString & "]")

just change the URL, and the variable to match your own

Try it with these...i need to do some debugging on the function when not searching based on attribute:

Local $sMyString = "newplaylist_popup"
$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[contains(@onclick," & $sMyString & ")]")
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.

Share this post


Link to post
Share on other sites

sample usage:

#include "C:AutomationEFLBrowser_generic.au3"
#include <Array.au3>
#include <IE.au3>
$oIE = _IECreate("http://msn.com")
_IELoadWait($oIE)
Local $sMyString = "Maps"
$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[contains(.," & $sMyString & ")]")
If IsArray($aObjects) Then
ConsoleWrite("Found matching elements=" & UBound($aObjects) & @CRLF)
_IEAction($aObjects[0], "focus")
_IEAction($aObjects[0], "click")
Else
ConsoleWrite("NO matching elements=" & @CRLF)
EndIf
Exit

or, you can do this

$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[.=" & $sMyString & "]")

just change the URL, and the variable to match your own

Try it with these...i need to do some debugging on the function when not searching based on attribute:

Local $sMyString = "newplaylist_popup"
$aObjects = BGe_IEGetDOMObjByXPathWithAttributes($oIE, "//a[contains(@onclick," & $sMyString & ")]")

Great this worked brilliantly. Thanks alot for all the help.

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