Jump to content

Problems with click on DIV element


Recommended Posts

It is possible using library IE.au3 to click on DIV element which has no attributes NAME and ID?

I have next HTML code

<div class="choicescontainer" style="z-index: 2; display: none;">
<div class="choices" dojoattachpoint="choices" style="width: 138px; height: 150px; overflow-x: hidden; overflow-y: scroll;">
    <div title="AMS">Amsterdam</div>
    <div title="EIN">Eindhoven</div>
    <div title="RTM">Rotterdam</div>
    <div title="AGA">Agadir</div>
    <div title="HER">Heraklion (Kreta)</div>
    <div title="HRG">Hurghada</div>
    <div title="IBZ">Ibiza</div>
    <div title="INN">Innsbruck</div>
    <div title="ADB">Izmir</div>
    <div title="AOK">Karpathos</div>
    <div title="TLN">Toulon (Hyères)</div>
    <div title="TOE">Tozeur</div>
    <div title="VLC">Valencia</div>
    <div title="VAR">Varna</div>
    <div title="TSF">Venetië (Treviso)</div>
    <div title="VRN">Verona</div>
    <div title="ZTH">Zakynthos</div>
</div>
</div>

I need to click on my DIV element (for example on <div title="RTM">Rotterdam</div>) but attributes NAME and ID are expected. In progress - browser window also may be hidden :-/

Maybe somebody knows how this to make?

Link to comment
Share on other sites

It is possible using library IE.au3 to click on DIV element which has no attributes NAME and ID?

I have next HTML code

<div class="choicescontainer" style="z-index: 2; display: none;">
<div class="choices" dojoattachpoint="choices" style="width: 138px; height: 150px; overflow-x: hidden; overflow-y: scroll;">
    <div title="AMS">Amsterdam</div>
    <div title="EIN">Eindhoven</div>
    <div title="RTM">Rotterdam</div>
    <div title="AGA">Agadir</div>
    <div title="HER">Heraklion (Kreta)</div>
    <div title="HRG">Hurghada</div>
    <div title="IBZ">Ibiza</div>
    <div title="INN">Innsbruck</div>
    <div title="ADB">Izmir</div>
    <div title="AOK">Karpathos</div>
    <div title="TLN">Toulon (Hyères)</div>
    <div title="TOE">Tozeur</div>
    <div title="VLC">Valencia</div>
    <div title="VAR">Varna</div>
    <div title="TSF">Venetië (Treviso)</div>
    <div title="VRN">Verona</div>
    <div title="ZTH">Zakynthos</div>
</div>
</div>

I need to click on my DIV element (for example on <div title="RTM">Rotterdam</div>) but attributes NAME and ID are expected. In progress - browser window also may be hidden :-/

Maybe somebody knows how this to make?

Here is technique:

$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv in $oDivs
    If String($oDiv.title) = "Izmir" Then 
        _IEAction($oDiv, "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

Get the collection and find the innertext you want:

$colDivTags = _IETagNameGetCollection($oIE, "div")
$iDivCnt = @extended
If $iDivCnt Then
    ConsoleWrite("Debug: There are " & $iDivCnt & " div tags" & @LF)
    $iDiv = 0
    For $oDivTag In $colDivTags
        $sInnerText = $oDivTag.innertext
        ConsoleWrite("Debug: Div tag " & $iDiv & ": InnerText = " & $sInnerText & @LF)
        If $sInnerText = "Rotterdam" Then
            ConsoleWrite("Debug: Found 'Rotterdam'" & @LF)
            ExitLoop
        EndIf
        $iDiv += 1
    Next
Else
    ConsoleWrite("Debug: There were no div tags" & @LF)
EndIf

:)

Oops, didn't see Dale was already here. But you need to check if you wanted the .title, or .innertext of the div. All the ConsoleWrite() is just to watch it work.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Faced such problem: in HTML code exist of two sets DIV tags with similar attributes title.

Click on need DIVs always arises in first set of DIV tags.

First DIVs set

<div class="choicescontainer" style="z-index: 2; display: none;">
    <div class="choices" dojoattachpoint="choices" style="width: 181px; height: 150px; overflow-x: hidden; overflow-y: scroll;">
        <div title="AMS">Amsterdam</div>
        <div title="EIN">Eindhoven</div>
        <div title="RTM">Rotterdam</div>
        <div title="AGA">Agadir</div>
        <div title="HER">Heraklion (Kreta)</div>
        <div title="HRG">Hurghada</div>
    </div>
</div>

And below in HTML code same set of DIV tags

<div class="choicescontainer" style="z-index: 2; display: none;">
    <div class="choices" dojoattachpoint="choices" style="width: 181px; height: 150px; overflow-x: hidden; overflow-y: scroll;">
        <div title="AMS">Amsterdam</div>
        <div title="EIN">Eindhoven</div>
        <div title="RTM">Rotterdam</div>
        <div title="AGA">Agadir</div>
        <div title="HER">Heraklion (Kreta)</div>
        <div title="HRG">Hurghada</div>
    </div>
</div>

For example:

First click necessary in first set on <div title="RTM">Rotterdam</div>, and next click in second set on <div title="AGA">Agadir</div>

This code does not decide problem:

$iDivNumber = 0
$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv in $oDivs
    If String($oDiv.title) = "RTM" Then
        $iDivNumber = $i
        _IEAction($oDiv, "click")
        ExitLoop
    EndIf
    $i+=1
Next

;some code skipped here

$oDivs = _IETagNameGetCollection($oIE, "div")
$i = 0
For $oDiv in $oDivs
    If $iDivNumber <> $i Then
        If String($oDiv.title) = "AGA" Then
            _IEAction($oDiv, "click")
            ExitLoop
        EndIf
    EndIf   
    $i+=1
Next

Somebody knows how to decide this problem?

Sorry for the my question, but i decide this problem with next code, maybe that will interesting to somebody or be useful in future

$iDivNumber = 0
$oDivs = _IETagNameGetCollection($oIE, "div")
For $oDiv in $oDivs
    If String($oDiv.title) = "RTM" Then
        $iDivNumber = $i
        _IEAction($oDiv, "click")
        ExitLoop
    EndIf
    $i+=1
Next

;some code skipped here

$oDivs = _IETagNameGetCollection($oIE, "div")
$i = 0
$k = 1
For $oDiv in $oDivs
    If $iDivNumber <> $i Then
        If String($oDiv.title) = "AGA" Then
            If $k <> 1 Then         
                _IEAction($oDiv, "click")
                ExitLoop            
            Else
                $k+=1
            EndIf           
        EndIf
    EndIf   
    $i+=1
Next
Edited by aproximator
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...