Jump to content
Sign in to follow this  

Latest Firefox clicks not working in FF.au3 mozrepl

Recommended Posts

Hi, I'm wondering if someone else faces this issue, or did I something wrong?

I'm using FF.au3 for some time quite well but problems started with Firefox v21. Even newer versions didn't work for me in some cases. So I stuck with FF v19. For different reasons I want to go to more recent version of firefox. But using all later versions seem to be incompatible. Reading values with xpath work quite well but not clicking on objects.

I found out same versions autoit/FF.au3/mozrepl and same script result in different responses from different Firefox:

Working sample FF v19

$sObj = ".//*[@id='memoryContent']/div[4]/div[3]/div/a[1]/img"
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate(".//*[@id='memoryContent']/div[4]/div[3]/div/a[1]/img",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLImageElement] - {querySelector: function() {...}, querySelectorAll: function() {...}, addEventListener: function() {...}, removeEventListener: function() {...}, dispatchEvent: function() {...}, style: {...}, src: "http..blabla-removed../images/card_back.jpg", ...}
__FFSend: try{FFau3.simulateEvent(FFau3.xpath,'MouseEvents','click');}catch(e){'_FFCmd_Err';};
__FFRecv: 1

Now same script running on FF v33 results in

_FFConnect: OS:    WIN_7 WIN32_NT 7601 Service Pack 1
_FFConnect: AutoIt:
_FFConnect: FF.au3:
_FFConnect: IP:
_FFConnect: Port:    4242
_FFConnect: Delay:     2ms
_FFConnect: Socket:     512
_FFConnect: Browser:    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
__FFSend: FFau3.xpath=null;try{FFau3.xpath=FFau3.WCD.evaluate(".//*[@id='memoryContent']/div[4]/div[3]/div/a[1]/img",FFau3.WCD,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;}catch(e){'_FFXPath_Error: '+e;};
__FFRecv: [object HTMLImageElement] - {alt: "", src: "http...blabla-removed.../images/card_back.jpg", crossOrigin: "", useMap: "", isMap: false, width: 130, height: 130, ...}
__FFSend: try{FFau3.simulateEvent(FFau3.xpath,'MouseEvents','click');}catch(e){e;};
__FFRecv: -3
_FFClick ==> No match: $sElement: FFau3.xpath

It doesn't find the element - why? Viewing the__FFRecv results from mozrepl 1.1.2 these are different.

Would be fine if anyone could help.

Share this post

Link to post
Share on other sites

Thanx Dan for your suggestion. I already tried your 'b14' without any change in result. Simple XPath objects are no problem. For me not working things are objects with events (i.e. js) attached. I try to find an example page so you can see whats the problem.

Share this post

Link to post
Share on other sites

I made a little example to show the differences. In Firefox v19 (maybe v21) this runs ok, but in v31 (or v33) even the first click on id 'turtle' results in 1 but nothing gets clicked. Would be fine if you could help!

#include <FF.au3>

_ffconnect("", 4242)
Sleep(5000) ; give page some time to finish loading
$nFrames = _FFGetLength("frames") ; count frames
ConsoleWrite("*** Frames:" & $nFrames & @CRLF) ; just for info

; following fails in Firefox > v21
_ffclick(_ffxpath("//*[@id='turtle']/div/img", "", 9)) ; choose first layout 'turtle'

    $nFreetiles = Number( _FFXPath(".//*[@class='tile']", "", 10)) ; count free tiles
Until $nFreetiles > 0 ; takes some time to load so wait for tiles
ConsoleWrite("*** Free tiles:" & $nFreetiles & @CRLF) ; just for info

Sleep(5000) ; show tiles before selecting one for demonstration
$oEvent = _ffxpath(".//*[@class='tile'][position()=1]", "", 9)
$res = _ffdispatchevent($oEvent, "mousedown") ; 'click' first tile
; this will show a light green frame on first free tile (often first tile in first row, upper left corner)
MsgBox(0, "Result of tile click", $res)
Edited by benlein

Share this post

Link to post
Share on other sites

Not shure why, but this works ;) Can you help me with next step selecting a tile this way?

Where can I find the syntax provided by "_FFCmd("FFau3.xpath.."?

I think the tiles require a 'mousedown' event.

Share this post

Link to post
Share on other sites

_FFXpath stores it's result in FFau3.xpath. The _FFCmd function is used to call the click method of the element found with _FFXpath.

You may want to take a look at _FFDisPatchEvent, which is supposed to support mouse events.

P.S. Are you really trying to automate a mahjong game? What's the goal here?

Share this post

Link to post
Share on other sites

Ok first item can be clicked now (turtle) but I'm still unable to click the tiles :( Did you try to let AU click a tile in actual Firefox version?

I did it with _FFDisPatchEvent which works in old version (see code above).

Its just an example page to explain my difficulties ;)

Edited by benlein

Share this post

Link to post
Share on other sites

Looks like it's a >context issue. You can modify FF.au3 by changing

_FFCmd('FFau3.simulateEvent=function simulateEvent(a,b,c){try{var d=document.createEvent(b);switch(b){case"MouseEvents":d.initMouseEvent(c,true,true,window,0,0,0,simulateEvent.arguments[4],simulateEvent.arguments[5],false,false,false,false,0,null);break;case"KeyboardEvent":d.initKeyEvent(c,true,true,null,false,false,false,false,simulateEvent.arguments[3],0);break;case"Event":d.initEvent(c,true,true);break}a.dispatchEvent(d);return 1}catch(e){return-3}return 0};')


_FFCmd('FFau3.simulateEvent=function simulateEvent(a,b,c){try{var d=FFau3.WCD.createEvent(b);switch(b){case"MouseEvents":d.initMouseEvent(c,true,true,window,0,0,0,simulateEvent.arguments[4],simulateEvent.arguments[5],false,false,false,false,0,null);break;case"KeyboardEvent":d.initKeyEvent(c,true,true,null,false,false,false,false,simulateEvent.arguments[3],0);break;case"Event":d.initEvent(c,true,true);break}a.dispatchEvent(d);return 1}catch(e){return-3}return 0};')

However, I haven't tested this and it may have a negative impact on other code.

The alternative is to manually execute the desired code using _FFCmd:

_ffxpath(".//*[@class='tile'][position()=1]", "", 9)

Share this post

Link to post
Share on other sites

Now  it works, thank you very much! I'll keep an eye on it, maybe create a second func in my udf in case I need old command.

Great support :thumbsup:

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  

  • Create New...