Hello Lennard,
thanks for providing me with a simpler test file!
There is good news and bad news.
The good news is, that there was a bug in calculating the coordinates
for the click in MozRepl::RemoteObject, I misunderstood the documentation.
The bad news is that sending a "click" event only works if the window
receiving the click event is the window element that currently has the
focus. I haven't been able to send a click to anything inside a frame
element.
If the following code works for your (frameless) target, that would be
great. If you have (i)frames on your page, I fear I'm out of ideas and
Google keywords.
sub __event {
my ($self,$type,@args) = @_;
my $fn;
if ($type eq 'click') {
$fn = $self->bridge->declare(<<'JS');
function(target,name,x,y) {
if(!x) x= 0;
if(!y) y= 0;
var r= target.getBoundingClientRect();
x+= r.left;
y+= r.top;
var d= target.ownerDocument;
var container= d.defaultView || window;
try {
var event = d.createEvent('MouseEvents');
event.initMouseEvent(name, true, true, container,
null, 0, 0, x, y, false, false, false,
false, 0, null);
target.dispatchEvent(event);
} catch(e) { "Caught Error: " + alert(e.message); };
}
JS
} else {
$fn = $self->bridge->declare(<<'JS');
function(target,name) {
var event = target.ownerDocument.createEvent('Events');
event.initEvent(name, true, true);
target.dispatchEvent(event);
}
JS
};
$fn->($self,$type,@args);
};
-max
Am 21.10.2014 um 10:30 schrieb Lennard Pfennig via RT:
Show quoted text> Queue: WWW-Mechanize-FireFox
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=99519 >
>
> Hi Max,
>
> Thanks a lot for the quick fix. I tried to adapt the changes but didn’t have the expected result.
> Is it enough to change the code on my local system, or do I have to compile something?
> ( I searched for the locations with "perldoc -lm ..” and added print “hallo”; to be sure that the code is called)
> Also I found a new testbed which I think is a bit cleaner:
>
>
http://jsfiddle.net/ZZEk8/632/ with:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use WWW::Mechanize::Firefox;
>
> my $mech = WWW::Mechanize::Firefox->new(activate => 1, autoclose => 0);
> $mech->get("
http://jsfiddle.net/ZZEk8/632/");
> $mech->click($mech->by_id("mama", single => 1), 10, 10);
>
> So, all in all, I’m happy to help, just tell me what to do.
> Lennard
>
>
>
>> On 18 Oct 2014, at 15:33, Max Maischein via RT <bug-WWW-Mechanize-FireFox@rt.cpan.org> wrote:
>>
>> <URL:
https://rt.cpan.org/Ticket/Display.html?id=99519 >
>>
>> Hello Lennart,
>>
>> I think this is a plain bug. Looking at my code, I see $x and $y
>> declared but never used in the subroutine, so it can't matter what you
>> pass in there. The actual problem lies even deeper, because
>> MozRepl::RemoteObject also does not support sending coordinates with the
>> mouse click.
>>
>> Your test page accesses event.pageX / event.pageY, which doesn't seem to
>> be supported by Firefox, but I have changes for MozRepl::RemoteObject
>> and WWW::Mechanize::Firefox that seem to work, see the recent patches to
>> the two repositories on
>>
>>
https://github.com/corion
>>
>> I'll see that I get new releases of both modules out this month, so if
>> the above changes work for you, you won't have to wait too long forthe
>> new version with the fix.
>>
>> -max
>>
>> Am 16.10.2014 um 23:06 schrieb Lennard Pfennig via RT:
>>> Queue: WWW-Mechanize-FireFox
>>> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=99519 >
>>>
>>> Hi again,
>>>
>>> some additional info and a testing system I found:
>>>
>>>
http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/
>>>
>>> on this site is a clickable image where u can see the coords u clicked.
>>> Whatever I say my code always clicks on -894 -914.
>>> Here the complete perl code I used for that:
>>>
>>> #!/usr/bin/perl.
>>> use strict;
>>> use warnings;
>>> use WWW::Mechanize::Firefox;
>>>
>>> my $mech = WWW::Mechanize::Firefox->new(activate => 1, autoclose => 0);
>>> $mech->get('
http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/');
>>> my $image = $mech->by_id('pointer_div', single => 1);
>>> $mech->click($image, 1000, 1000);
>>> print "done\n";
>>>
>>> Am I doing it wrong?
>>> Greetings
>>> Lennard
>>>
>>> On Mi, 2014-10-15 at 15:36 -0400, Bugs in WWW-Mechanize-FireFox via RT
>>> wrote:
>>>> Greetings,
>>>>
>>>> This message has been automatically generated in response to the
>>>> creation of a trouble ticket regarding:
>>>> "bug when using coords in clicking",
>>>> a summary of which appears below.
>>>>
>>>> There is no need to reply to this message right now. Your ticket has been
>>>> assigned an ID of [rt.cpan.org #99519]. Your ticket is accessible
>>>> on the web at:
>>>>
>>>>
https://rt.cpan.org/Ticket/Display.html?id=99519
>>>>
>>>> Please include the string:
>>>>
>>>> [rt.cpan.org #99519]
>>>>
>>>> in the subject line of all future correspondence about this issue. To do so,
>>>> you may reply to this message.
>>>>
>>>> Thank you,
>>>> bug-WWW-Mechanize-FireFox@rt.cpan.org
>>>>
>>>> -------------------------------------------------------------------------
>>>> Hi,
>>>>
>>>> I'm having a problem with the click method from WWW::Mechanize::Firefox
>>>> when using the optional arguments for coords.
>>>>
>>>> my code:
>>>> $mech->click($image, $x, $y);
>>>>
>>>> I noticed this while watching wireshark and the sendet packages, where I
>>>> saw that the coords for x and y always stayed at x=0 y=0.
>>>>
>>>> Looking foorward for your answer
>>>> Lennard
>>>>
>>>
>>>
>>>
>>
>>
>
>