Sign in to follow this  
Followers 0
benlein

Latest Firefox clicks not working in FF.au3 mozrepl

11 posts in this topic

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"
$res=_FFClick(_FFXpath($sObj,"",9))
__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:    3.3.12.0
_FFConnect: FF.au3:    0.6.0.1b-10
_FFConnect: IP:    127.0.0.1
_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



I recently posted an updated version of ff.au3 that addresses a few outstanding issues. You may want to give it a try to see if your issue has already been addressed in a later revision of the UDF.

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

That would be helpful. Also, what is the actual website that you are attempting to automate?

Not sure if this will help in this case, but you could try setting $_FF_COM_TRACE = True to perhaps get a better look at whats happening under the hood.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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!

$_FF_COM_TRACE = True
#include <FF.au3>

_ffconnect("127.0.0.1", 4242)
_FFOpenUrl("http://mahjong.../?fullscreen")
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'

Do
    Sleep(1000)
    $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)
Exit
Edited by benlein

Share this post


Link to post
Share on other sites

Try changing:

_ffclick(_ffxpath("//*[@id='turtle']/div/img", "", 9))

to:

_ffxpath("//*[@id='turtle']/div/img", "", 9)

_FFCmd("FFau3.xpath.click()")

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

#9 ·  Posted (edited)

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};')

to

_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)
_FFCmd("d=FFau3.WCD.createEvent('MouseEvent');d.initMouseEvent('mousedown',true,true,window,0,0,0,0,0,0,0,0,0,0,null);FFau3.xpath.dispatchEvent(d);")
1 person likes this

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  
Followers 0