Jump to content

Latest Firefox clicks not working in FF.au3 mozrepl


benlein
 Share

Go to solution Solved by Danp2,

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"
$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.

Link to comment
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.

Link to comment
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!

$_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
Link to comment
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
Link to comment
Share on other sites

  • Solution

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);")
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...