grakker

FF.au3 Javascript Click on Button Question

7 posts in this topic

I have a page with a bunch of links that look like this:

<input type="submit" name="ctl00$MainContent$DroppedStudents$ClassRptr$ctl01$btnStuProfile" value="" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$DroppedStudents$ClassRptr$ctl01$btnStuProfile&quot;, &quot;&quot;, false, &quot;&quot;, &quot;Helpers/SetStudentAndRedirect.aspx?DU=StudentProfile.aspx&amp;SN=3720&quot;, false, false))" id="ctl00_MainContent_DroppedStudents_ClassRptr_ctl01_btnStuProfile" title="View Student Profile" class="dim-link student-profile" />

I'm able to parse the page and end up with an array of `name` references that look like this:
 

ctl00$MainContent$ClassRptr$ctl01$btnStuProfile
ctl00$MainContent$ClassRptr$ctl02$btnStuProfile
ctl00$MainContent$ClassRptr$ctl03$btnStuProfile
ctl00$MainContent$ClassRptr$ctl04$btnStuProfile
ctl00$MainContent$ClassRptr$ctl05$btnStuProfile

I can't figure out how to use the Firefox UDF to click on these. I have installed and tested MozRepl and it works. I want to do something like:

For $row in $array
    _FFLinkClick($row, "name")
Next

Well, I'm going to do more than just click those links, but I can't even get that to work. Right now my error looks like:

_FFConnect: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_FFConnect: AutoIt: 3.3.14.2
_FFConnect: FF.au3: 0.6.0.1b-15
_FFConnect: IP: 127.0.0.1
_FFConnect: Port:   4242
_FFConnect: Delay:  2ms
_FFConnect: Socket:     580
_FFConnect: Browser:    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
__FFSendJavaScripts: Sending functions to FireFox .......... done
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate("//a[contains(@name,'ctl00$MainContent$ClassRptr$ctl01$btnStuProfile')]",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: _FFXPath_Error: TypeError: can't access dead object
__FFSend: try{FFau3.simulateEvent(0,'MouseEvents','click');}catch(e){'_FFCmd_Err';};
_FFXPath ==> Error return value: _FFXPath_Error: TypeError: can't access dead object
__FFRecv: -3

I have looked at the samples, but I just can't figure out how to do this. I think that it is something with _FFXPath, but that documentation stumps me as well.

Share this post


Link to post
Share on other sites



_FFDialogWait should be what you are searching for.

Share this post


Link to post
Share on other sites

I don't think that is what I'm looking for. Basically, I have a page with a list of links. Each link I want to click, wait for the page to open, process it (this part I have working!), then close it and click the next link. This ends up being between 100-200 links. Tedious to not automate.

Share this post


Link to post
Share on other sites

Hard to say without seeing your script. :blink:

Have you tried setting the active window by calling _FFWindowSelect?

Share this post


Link to post
Share on other sites

Here is most of the script:

 

#Include <FF.au3>
#Include <Array.au3>

;open source page, copy and close
WinWait("https://aeries.hbuhsd.edu/Aeries.net/TeacherAttendance.aspx - Mozilla Firefox")
send("^u")
Sleep(1550)
Send("^a")
Send("^c")
$raw = ClipGet()
Send("^x")

$Source = StringSplit($raw, @LF, 1)
;_ArrayDisplay($Source)
Global $Just_Links = []

;Take the entire page and parse out the links
For $i = 1 to $Source[0]
    If Stringinstr($Source[$i], "ctl00_MainContent_ClassRptr_") And StringInStr($Source[$i], "btnStuProfile") Then
        $Source[$i] = StringMid(StringStripWS($Source[$i], 4), 29, 47)
        ;$Source[$i] = Stringreplace($Source[$i], "$", "_")
        _ArrayAdd($Just_Links, $Source[$i])
    EndIf
Next

_ArrayDelete($Just_Links, 0)
;_ArrayDisplay($Just_Links)

If _FFConnect(Default, Default, 3000) Then
    for $row In $Just_Links
        WinWaitActive("Class Attendance")
        Sleep(1000)
        _FFLinkClick($row, "name")
    Next
EndIf

The only trouble I'm having is the loop.

Share this post


Link to post
Share on other sites
9 minutes ago, grakker said:

The only trouble I'm having is the loop.

i understood your trouble is a JS-Window, sorry for my missunderstanding and good luck.

Share this post


Link to post
Share on other sites

Have you tried using _FFReadHTML to capture the page source? I would expect that to work much better than your current method.

You could also use _FFLinksGetAll to get an array of all links and then process the array to find the desire links.

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

  • Similar Content

    • milos83
      By milos83
      How can I check if element is focused in Firefox using FF.au3 UDF?
      This is my try:
      I have prepared a function that checks if the object is focused:
       
      _FFCmd('FFau3.isfocused=function isfocused(a){try{return (a === document.activeElement)}catch(e){return}}') $oElm = _FFXPath("//*[@id='someId']") ConsoleWrite(_FFIsFocused($oElm)) Func _FFIsFocused($sElement = "") Local $isFoc = _FFCmd("FFau3.isfocused(" & $sElement & ")") Return $isFoc EndFunc ;==>_FFIsFocused Now, the javascript part is tested and it does return successfully.
      After a lot of try/fails I inserted an alert box in order to display the object being compared.
      Here is what I got
       
      The focused object is: [object XULElement]
      The object that I send for comparing is [object HTMLInputElement]
      Why is that?
       
       
    • Chimp
      By Chimp
      Hi all.
      I'm playing a bit with the ScriptControl object using as base this example by @genius257.
      here is a very simple try, ... but it fails. what I'm doing wrong?
      Local $oSC = ObjCreate("ScriptControl") $oSC.Language = "JScript" $oSC.ExecuteStatement('alert("I am a javascript alert box!");') MsgBox(0,'AutoIt','Pause') Thanks
    • spuuunit
      By spuuunit
      Is it possible to know if a textbox is active in FireFox?
       
      This is what I want:
      if (Textbox in FireFox == Active) { }
    • steveeye
      By steveeye
      Hi, what else can we add in <table> besides <tr> & <td> to make it more interative to the users?