Jump to content

How to get an object from this:


SnoozeAr
 Share

Recommended Posts

I'm trying to click this but can't figure out how to get an object from it. I can get one from the ReportBox but when I click on that all it does is check or uncheck. I can't figure out how to get an object from it when it doesn't have an ID or Name. I need to fire an onclick event by simulating a mouse click.

<TR><TD style="BACKGROUND-COLOR: #a6caf0" onclick=ChangeBackground(event,498,1); width="4%" align=middle><INPUT onclick=BoxChecker(498) value=241203704 CHECKED type=checkbox name=ReportBox></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width="12%" align=left><SPAN style="CURSOR: hand" class=status_table onclick=GetFile(498)>241203704</SPAN></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width="15%" align=left><SPAN style="COLOR: #aa2222; CURSOR: hand" class=status_table onclick=GetFile(498)>Retrieved</SPAN></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width="29%" align=left><SPAN style="CURSOR: hand" class=status_table onclick=GetFile(498)>WSWMI -March 2010-1416302 </SPAN></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width="11%" noWrap align=left><SPAN style="CURSOR: hand" class=status_table onclick=GetFile(498)>&nbsp;2010-12-16 08:01:21</SPAN></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width="13%" align=middle><SPAN style="CURSOR: hand" class=status_table onclick=GetFile(498)>3.43Kb</SPAN></TD>
<TD style="BACKGROUND-COLOR: #a6caf0" width=* noWrap align=left><SPAN style="CURSOR: hand" class=status_table onclick=GetFile(498)>&nbsp; &nbsp; Excel</SPAN></TD></TR>
Link to comment
Share on other sites

Exactly what did you try? For example, under _IEAction() there are multiple techniques given (just "click", setting "focus" first, setting "focus" then using ControlSend, etc.)

:x

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

Oops, my mistake. Misread the OP and didn't see where the trouble was. :P

You can get the collection of TD tags with _IETagNameGetCollection(), then walk through the collection looking for an $oTD with whatever attribute you want, like $oTD.innerText & "" = "Retrieved".

Or, once you have a reference to ReportBox, you can get sibling TDs with $oTD.nextSibling in a loop.

:x

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

Ok, I'm stumped again. I got the object but it still won't click on it. There are 0 console errors so I'm not sure what's going on.

$oCollection = _IETagNameGetCollection($o_form3, "TD")
For $oElement In $oCollection
If $oElement.innerText = $reportnumber Then ; It finds the correct one. I verified with a msgbox. 
    $oObject = $oElement
    $isobj = IsObj($oObject) ;It returns 1
    MsgBox(0, "", $isobj)
    _IEAction($oObject, "click")    ; Tried all of these and it still didn't fire.
    $oObject.FireEvent("onclick")
    $oObject.fireEvent("onmouseover") 
    $oObject.fireEvent("onmousedown")
    $oObject.fireEvent("onmouseup")
    MsgBox(0, "", "Done, Didn't open") ; to let me know it didn't work.
EndIf
Next
Link to comment
Share on other sites

You don't show how you verified it found the right TD element. Your IsObj() doesn't do it because it will be true for all the $oElement items, matching or not. Also, the MsgBox() "Done" doesn't help because it comes up unconditionally.

The first concern is that you test with $oElement.innerText = $reportnumber without first making sure the variable types match, so you might have false matches. This could help check it:

ConsoleWrite("$reportnumber = " & $reportnumber & @LF)
$oCollection = _IETagNameGetCollection($o_form3, "TD")
$iTag = 0
For $oElement In $oCollection
    $f_Match = (String($oElement.innerText) = String($reportnumber))
    ConsoleWrite($iTag & ": innerText = " & $oElement.innerText & "; match = " & $f_Match & @LF)
    $iTag += 1
Next

This should show you a line for every TD element, the .innerText that goes with each, and if it is seen as a match.

Assuming you DO have the right element, try the "focus" then ControlSend() method.

:x

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

You don't show how you verified it found the right TD element. Your IsObj() doesn't do it because it will be true for all the $oElement items, matching or not. Also, the MsgBox() "Done" doesn't help because it comes up unconditionally.

The first concern is that you test with $oElement.innerText = $reportnumber without first making sure the variable types match, so you might have false matches. This could help check it:

ConsoleWrite("$reportnumber = " & $reportnumber & @LF)
$oCollection = _IETagNameGetCollection($o_form3, "TD")
$iTag = 0
For $oElement In $oCollection
    $f_Match = (String($oElement.innerText) = String($reportnumber))
    ConsoleWrite($iTag & ": innerText = " & $oElement.innerText & "; match = " & $f_Match & @LF)
    $iTag += 1
Next

This should show you a line for every TD element, the .innerText that goes with each, and if it is seen as a match.

Assuming you DO have the right element, try the "focus" then ControlSend() method.

:x

It found the right element. I also tried "focus" but it still was unable to execute the onclick event. Let's say it's not possible to click on it. How would I go about running the jscript from the page? onclick=GetFile(ID)

568: innerText = 241204253; match = True

Also, here is my code that finds the elements that are "Retrieved" then verifies that the checkbox is checked. After that is my code to get the object and click it.

$iCount = 0
For $z = 0 To UBound($aTableData,1) - 1
If $iCount = 100 Then
ExitLoop
EndIf
If StringInStr($aTableData[$z][2], "Retrieved") Then 
$reportnumber = $aTableData[$z][1]
$Checkbox = _IEFormElementCheckboxSelect($o_form3, $reportnumber, "", -1)
$iCount += 1
If $checkbox = "true" Then
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...