DaLiMan

IE object get BACKGROUND_IMAGE

23 posts in this topic

Hi,

I'm trying to get the state of a button in a website at work.
The state is made visible for the user by showing him a green V or a red X.
This however, is done by an image in the button itself.

Is there anyway to get the BACKGROUND-IMAGE url from the _IEobject ?

 

<INPUT name=ctl00$cph$CustomerDataGrid$ctl05$Month1Button class=MonthButton id=ctl00_cph_CustomerDataGrid_ctl05_Month1Button style="HEIGHT: 24px; WIDTH: 26px; BACKGROUND-IMAGE: url(../../Css/Icons/check_16.gif); BACKGROUND-REPEAT: no-repeat; BACKGROUND-POSITION: center 50%" type=submit value=" ">

 

The code below is working when I want to click the button.
But how to get the Image returned??

check_16.gif = V
close_16.gif = X
 

#include <Array.au3>
#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $xnr, $oIE, $oDiv, $cRowCount, $cArtNum_IE, $oButton

; Maak verbinding met de website
$oIE = _IEAttach("http://intranet/CustomerBonus/Pages/Admin/ManageCustomergroupMemberships.aspx", "url")

; Verkrijg de DataGrid aantal regels
$oDiv = _IEGetObjById($oIE, "ctl00_cph_CustomerDataGrid")

    $oButton = _IEGetObjByName($oIE, "ctl00_cph_CustomerDataGrid_ctl05_Month1Button")
    _IEAction($oButton, "click")

 

Share this post


Link to post
Share on other sites



$oButton.innerhtml

And then search for the string "check_16.gif".

Share this post


Link to post
Share on other sites
47 minutes ago, Juvigy said:
$oButton.innerhtml

And then search for the string "check_16.gif".

That gives me an empty string...?

 

It made me think about searching for it in the complete HTML.
However, I thought there should be a better way...

 

$oIE = _IEAttach("http://intranet/CustomerBonus/Pages/Admin/ManageCustomergroupMemberships.aspx", "url")
$oIE_HTML = _IEBodyReadHTML($oIE)

;Set default value, since there are only 2
$oButtonState = "V"

; Get needed string to search in.
$iStart = StringInStr($oIE_HTML, "ctl00$cph$CustomerDataGrid$ctl19$Month9Button")
$iStop = StringInStr($oIE_HTML, "BACKGROUND-REPEAT",0,1,$iStart)
$oButtonStateString = StringMid($oIE_HTML, $iStart, $iStop - $iStart)

;Change value when needed.
If StringInStr($oButtonStateString, "close_16") > 0 Then $oButtonState = "X"

 

Share this post


Link to post
Share on other sites
39 minutes ago, Subz said:

Try something like:

#include <Array.au3>
#include <IE.au3>

$oIE = _IECreate('http://dynamicdrive.com/dynamicindex5/button2.htm', 1)
$oInputs = _IETagnameGetCollection($oIE, "input")
For $oInput In $oInputs
    If $oInput.value = 'Yahoo' Then
        ConsoleWrite('Button style : ' & $oInput.currentstyle.backgroundImage & @CRLF)
    EndIf
Next

 

Thank you Subz!

I have this working for my website and I get a list of the images .
Is it also possible to refer to the .backgroundimage by name like object.name("ctl00$cph$CustomerDataGrid$ctl06$Month1Button").backgroundimage?

 

Share this post


Link to post
Share on other sites

You should be able to use:

For $oInput In $oInputs
    If $oInput.name = 'ctl00$cph$CustomerDataGrid$ctl05$Month1Button' Then
        ConsoleWrite('Button style : ' & $oInput.currentstyle.backgroundImage & @CRLF)
    EndIf
Next

 

Share this post


Link to post
Share on other sites
4 minutes ago, Subz said:

You should be able to use:

For $oInput In $oInputs
    If $oInput.name = 'ctl00$cph$CustomerDataGrid$ctl05$Month1Button' Then
        ConsoleWrite('Button style : ' & $oInput.currentstyle.backgroundImage & @CRLF)
    EndIf
Next

 

Yes, but I have 12 months for over 50 customers. (could be less / more )
What I thought would be best is to loop trough the rows of customers and then have a loop 1 to 12 for each month button by name and getting the image.

An extra for...next looping through all $oinputs would slow things considerably down since there are 662 items ($oInputs) on the page.

Do I make sence? ^_^

 

 

Share this post


Link to post
Share on other sites

No :P, are you able to send through a screenshot of what you mean, are the buttons all on one page or do you have to click one first?  Are the names dynamic or does button1 - button12 the only change?

 

Share this post


Link to post
Share on other sites

This is the screenshot of a piece of the site.
I'm trying to get all  the customer numbers and names with their values per month.
 

I have a piece of code that attaches to the website and then loops trough each row an gets the data according.
This is working fine for the numbers and name since they have values.
The monthly V or X has no value, but is made visible through the icon in the button.
So instead of searching for the button text in the HTML and the searching for the icon name I hoped it would be possible to get the data by directly referring to it by object.reference.

Something like $obj.name("something").backgroundimage
 

 

#include <Array.au3>
#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $xnr, $oIE, $oIE_HTML, $oDiv, $cRowCount, $oButton
Local $oButtonState, $oButtonStateString, $iStart, $iStop
Local $DebString, $d

; Connect to website
$oIE = _IEAttach('http://intranet/CustomerBonus/Pages/Admin/ManageCustomergroupMemberships.aspx', 'url')

; Get DataGrid row numbers
$oDiv = _IEGetObjById($oIE, 'ctl00_cph_CustomerDataGrid')
$cRowCount = $oDiv.rows.length
ConsoleWrite("ROWS: " & $oDiv.rows.length & @LF)

; Get Customer number and name and put in Clipboard.
For $a = 1 to $cRowCount - 2
    $DebString = $DebString & $oDiv.rows($a).cells(0).innertext & @TAB & $oDiv.rows($a).cells(1).innertext & @CRLF
Next
ClipPut($DebString)

Exit


 

YesNo.png

Share this post


Link to post
Share on other sites

#10 ·  Posted

Also just tried    $oDiv.rows(1).cells(3).background  with no luck.

Share this post


Link to post
Share on other sites

#11 ·  Posted

I was just thinking of something like this:

#include <Array.au3>
#include <IE.au3>
$oIE = _IECreate('http://dynamicdrive.com/dynamicindex5/button2.htm', 1)
$oInputs = _IETagnameGetCollection($oIE, "input")
For $oInput In $oInputs
    _Get_BackGround($oInput, 'AlltheWeb')
    _Get_BackGround($oInput, 'Google')
    _Get_BackGround($oInput, 'Yahoo')
Next

Func _Get_BackGround($oCurrent, $sInputName)
    If $oCurrent.value = $sInputName Then
        ConsoleWrite('Button style : ' & $oCurrent.currentstyle.backgroundImage & @CRLF)
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I can get that working for my script I guess.
But that is just another for..next loop.

I just like to know if it is possible to not use a loop?

Edited by DaLiMan
Was not finished typing....

Share this post


Link to post
Share on other sites

#13 ·  Posted

Are you able to provide a few lines of code so I can test?

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

24 minutes ago, Subz said:

Are you able to provide a few lines of code so I can test?

 

Here a piece of the sourcecode.
I was not able to get the images working, but the code is the same.

 

ToeUit.html

Edited by DaLiMan

Share this post


Link to post
Share on other sites

#15 ·  Posted

I am wondering why the .innerHTML returns empty string.

@Subz

Any idea?

Share this post


Link to post
Share on other sites

#16 ·  Posted

Is this something we can use to refer to?

YesNo_style.png

Share this post


Link to post
Share on other sites

#17 ·  Posted

#include <Array.au3>
#include <IE.au3>
$oIE = _IEAttach('http://intranet/CustomerBonus/Pages/Admin/ManageCustomergroupMemberships.aspx', 'url')
$otrs = _IETagnameGetCollection($oIE, "tr")
Local $aCustomer[1][14]
Local $bHeader = False
For $otr In $otrs
    $otds = _IETagNameGetCollection($otr, "td")
    If $otds.length < 16 Then ContinueLoop
    $i = 0
    ReDim $aCustomer[UBound($aCustomer) + 1][14]
    For $otd In $otds
        If $i = 0 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][0] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][0] = $otd.innertext
        EndIf
        If $i = 1 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][1] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][1] = $otd.innertext
        EndIf
        If $i = 3 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][2] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][2] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 4 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][3] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][3] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 5 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][4] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][4] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 6 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][5] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][5] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 7 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][6] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][6] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 8 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][7] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][7] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 9 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][8] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][8] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 10 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][9] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][9] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 11 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][10] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][10] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 12 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][11] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][11] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 13 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][12] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][12] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        If $i = 14 Then
            If $bHeader = False Then
                $aCustomer[UBound($aCustomer) - 1][13] = $otd.innertext
                $bHeader = True
            EndIf
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][13] = $otd.firstchild.firstchild.currentstyle.backgroundImage
        EndIf
        $i += 1
    Next
Next
_ArrayDisplay($aCustomer)

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

:blink: wow...

How do you come up with this...briljant!

Had an error at this line. After comment-out it is still working perfectly.

Thanx very much Subz, I'm gonna use your code in my script.
(...I can throw away everything I made before...This does it all!)

If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][13] = $otd.firstchild.firstchild.currentstyle.backgroundImage

 

Share this post


Link to post
Share on other sites

#19 ·  Posted

Glad it works, I realised now that you wanted to replace the url with V or X so updated the code here, you just need to change the URL path in the _Get_Background function.

 

#include <Array.au3>
#include <IE.au3>
$oIE = _IEAttach('http://intranet/CustomerBonus/Pages/Admin/ManageCustomergroupMemberships.aspx', 'url')
$otrs = _IETagnameGetCollection($oIE, "tr")
Local $aCustomer[1][14]
Local $bHeader = False
For $otr In $otrs
    $otds = _IETagNameGetCollection($otr, "td")
    If $otds.length < 16 Then ContinueLoop
    $i = 0
    ReDim $aCustomer[UBound($aCustomer) + 1][14]
    For $otd In $otds
        If $i = 0 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][0] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][0] = $otd.innertext
        EndIf
        If $i = 1 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][1] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][1] = $otd.innertext
        EndIf
        If $i = 3 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][2] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][2] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 4 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][3] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][3] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 5 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][4] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][4] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 6 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][5] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][5] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 7 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][6] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][6] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 8 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][7] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][7] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 9 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][8] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][8] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 10 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][9] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][9] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 11 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][10] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][10] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 12 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][11] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][11] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 13 Then
            If $bHeader = False Then $aCustomer[UBound($aCustomer) - 1][12] = $otd.innertext
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][12] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        If $i = 14 Then
            If $bHeader = False Then
                $aCustomer[UBound($aCustomer) - 1][13] = $otd.innertext
                $bHeader = True
            EndIf
            If $bHeader = True Then $aCustomer[UBound($aCustomer) - 1][13] = _Get_BackGround($otd.firstchild.firstchild.currentstyle.backgroundImage)
        EndIf
        $i += 1
    Next
Next
_ArrayDisplay($aCustomer)
Func _Get_BackGround($sBackGround)
    If $sBackGround = 'url("/close_16.gif")' Then Return 'X'
    If $sBackGround = 'url("/check_16.gif")' Then Return 'V'
    Return ''
EndFunc

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

@Juvigy Inputs don't have innerhtml, technically you could do it from the parentnode which is a span as span can include innerhtml.  Hope that makes sense.

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