Workaround for lack of DS mouse commands

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Workaround for lack of DS mouse commands

by davidpoor on Tue Nov 06, 2012 2:12 pm

iMacros for Firefox does not support DS commands or the SIZE command so we need a work-around if we need to properly control mouse events. .

This workaround is for times when you need explicit mouse events: mouse down, mouse up, double click, or click. (The click event is needed when the TAG command does not work).

To simulate the DS commands by positioning, you would need accurate X/Y locations which are relative to the left and top of the active screen. However, many many web pages are centered when there is a large active area, so the X coordinates may not be valid. While it may be possible to recalculate the X/Y coordinates based on the actual screen area, it is, at best, difficult to issue mouse commands by X/Y coordinates alone.

So, this is based first on (a) locating the HTML object, and then (b) issuing a "Mouse Event" for that object.

DS_Mouse.iim: Save the following as DS_Mouse.iim (it should be all one very long line):
Code: Select all
URL GOTO=javascript:var<SP>_DS_button="LMR".indexOf("{{_DS_Command}}".charAt(0));if(_DS_button<0){_DS_button=0;}var<SP>_DS_fn="click";switch("{{_DS_Command}}".substring(1)){case<SP>"DOWN":_DS_fn="mousedown";break;case<SP>"UP":_DS_fn="mouseup";break;case<SP>"DBLCLK":_DS_fn="dblclick";break;case<SP>"OVER":_DS_fn="mouseover";_DS_button=0;}var<SP>_DS_obj=document.getElementById("{{_DS_ObjectId}}");var<SP>_DS_event=document.createEvent("MouseEvents");_DS_event.initMouseEvent(_DS_fn,1,1,window,0,0,0,0,0,0,0,0,0,_DS_button,null);_DS_obj.dispatchEvent(_DS_event);_DS_obj.focus();


USING DS_Mouse.iim:

In your controlling program, set the id of the HTML object and the command to be executed, then call the macro.

    The HTML object must have an id attribute, e.g. <div id="someElementId">. If the target object does not have an id, you will need to modify the macro and use a different technique to select the HTML object.

    The function must be one of the supported DS Functions:

      Mouse position: MOVETO
      Left button: CLICK, LDOWN, LUP, LDBLCLK
      Middle button: MDOWN, MUP, MDBLCLK
      Right button: RDOWN, RUP, RDBLCLK

To control the mouse, you need only add three lines to your program such as:
Code: Select all
   iimSet("_DS_ObjectId","someElementid");
   iimSet("_DS_Command","LDOWN");
   iimPlay("DS_Mouse.iim");


TECHNICAL: The _DS_Mouse.iim macro uses javascript to create and execute a mouse event on the specified object, using
the following code:

Code: Select all
URL GOTO=javascript:

//  NOTE:  Because the variables are all global, they are relatively long

//  Get the button: 0=left, 1=middle, 2=right
var _DS_button="LMR".indexOf("{{_DS_Command}}".charAt(0));
if (_DS_button<0){_DS_button=0;}

//  Convert the DS Command to a mouse eventr function
var _DS_fn="click";
switch("{{_DS_Command}}.substring(1)){
    case "DOWN":_DS_fn="mousedown"; break;
    case "UP":_DS_fn="mouseup"; break;
    case "DBLCLK":_DS_fn="dblclick";break;
    case "OVETO":_DS_fn="mouseover";
_DS_button=0;}
   
//  Get the target   
var _DS_obj=document.getElementById("{{_DS_ObjectId}}");

//  Create and dispatch the mouse event
var _DS_event=document.createEvent("MouseEvents");
_DS_event.initMouseEvent(_DS_fn,1,1,window,0,0,0,0,0,0,0,0,0,_DS_button,null);
_DS_obj.dispatchEvent(_DS_event);

//  The following is here only to prevent the javascript from being treated as a new page to display
_DS_obj.focus();


The actual macro is made up of the following lines concatenated together

Code: Select all
URL<SP>GOTO=javascript:
var<SP>_DS_button="LMR".indexOf("{{_DS_Command}}".charAt(0));
if(_DS_button<0){_DS_button=0;}
var<SP>_DS_fn="click";
switch("{{_DS_Command}}.substring(1)){
case<SP>"DOWN":_DS_fn="mousedown";break;
case<SP>"UP":_DS_fn="mouseup";break;
case<SP>"DBLCLK":_DS_fn="dblclick";break;
case<SP>"OVETO":_DS_fn="mouseover";_DS_button=0;}
var<SP>_DS_obj=document.getElementById("{{_DS_ObjectId}}");
var<SP>_DS_event=document.createEvent("MouseEvents");
_DS_event.initMouseEvent(_DS_fn,1,1,window,0,0,0,0,0,0,0,0,0,_DS_button,null);
_DS_obj.dispatchEvent(_DS_event);
_DS_obj.focus();


November 15, 2012: Added support for MOVETO as "mouseover" event.
Last edited by davidpoor on Thu Nov 15, 2012 10:33 am, edited 1 time in total.
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

Re: Workaround for lack of DS mouse commands

by tgandy on Thu Nov 08, 2012 5:07 am

Thanks, I'll give it a go.

Some recent changes to either the web application, Firefix or iMacros has caused values put into the combo search boxes to be ignored. This has stopped most of my macros.

This might be a solution.

Thanks,
Andy
tgandy
 
Posts: 14
Joined: Wed Nov 04, 2009 1:59 am

Re: Workaround for lack of DS mouse commands

by janib4all on Thu Nov 15, 2012 12:26 am

Great tutor, though it does not work for me (perhaps I'm missing something) but anyhow, I was wondering if you got some solution related with Ajax - I mean, I've been looking around everywhere to fine some solution but couldn't find a single clue. Basically, I'm trying to automate sending email through my gMail account; with the standard (old) version, it's easy but their new fully ajax based template doesn't allow me to add anything to main body the email and don't identify 'Send' button.

Any suggestions would be highly appreciated!
Hire the BoT-fReeak!
botspecialist.blogspot.com
janib4all
 
Posts: 132
Joined: Tue Jul 20, 2010 11:44 pm
Location: Karachi, Sindh, Pakistan

Re: Workaround for lack of DS mouse commands

by davidpoor on Thu Nov 15, 2012 5:44 am

If you can be a little more specific with the "though it does not work for me", I will be happy to try to replicate your issue and get back to you. Note, however, that I have only looked at this with the Firefox version.

As for injecting text contents for your e-mail, you should be able to use the same approach with keyboard events to "type" in the sequence of characters you need. See my post on How to Simulate a Keypress using Javascript http://forum.iopus.com/viewtopic.php?f=6&t=19233#p49565
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

Re: Workaround for lack of DS mouse commands

by inter on Wed Dec 05, 2012 9:23 am

I'm trying to simulate the mouseover event that was in previous versions.

I've been playing around with your code and I'm able to correctly target the element, but I'm not able to mouseover without having the script click the element as well.

My javascript file only consists of:

iimSet("_DS_ObjectId","b070153850_0");
iimSet("_DS_Command","OVER");
iimPlay("DS_Mouse.iim");

Am I missing something to get this working the way I need or is it not possible?

Thanks!
inter
 
Posts: 5
Joined: Wed Jan 25, 2012 11:43 am

Re: Workaround for lack of DS mouse commands

by inter on Wed Dec 05, 2012 9:26 am

I fixed it by changing var<SP>_DS_fn="click"; to var<SP>_DS_fn="mouseover"; in the original macro.

Thanks for this, it appears to be extremely useful!
inter
 
Posts: 5
Joined: Wed Jan 25, 2012 11:43 am

Re: Workaround for lack of DS mouse commands

by davidpoor on Wed Dec 05, 2012 12:03 pm

Re inter's question on mouseover:

Using the naming conventions of DS mouse commands, the MOVETO command is equivalent to placing the mouse over the specified object. Try the following with the original macro as posted:

iimSet("_DS_ObjectId","b070153850_0");
iimSet("_DS_Command","MOVETO");
iimPlay("DS_Mouse.iim");

PS: Your change worked only because "OVER" is not a recognized command. The mouse action defaults to "click" and is then overridden by the CASE statement for each other valid command. Since OVER Is not in the set, the action defaulted to "click" and you changed the behavior of CLICK to be "mouseover".
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

Re: Workaround for lack of DS mouse commands

by inter on Thu Dec 06, 2012 7:21 am

I actually tried the same code you posted with no luck and I feel as if I'm missing something (which is entirely possible).

I see DOWN, UP, DBLCLK, and OVER commands in your initial DS_Mouse.iim macro line, but in the next two "breakdown" examples the OVER command has been changed to OVETO. I initially tried both MOVETO and OVETO in my script, but neither worked so I'm unsure what the issue was.

As I said, I got things working for my purposes, but thought I might point it out for anyone in the future.
inter
 
Posts: 5
Joined: Wed Jan 25, 2012 11:43 am

Re: Workaround for lack of DS mouse commands

by joiner on Tue Dec 11, 2012 1:04 am

if have a html tag from imacro 's complete html tag as:

TAG POS=1 TYPE=DIV ATTR=ID:event_div&&CLASS:click&&TITLECONTENT:<div<SP>class="build_tip"><h3<SP>class="build_name<SP>zb_color7">market<SP>(level:10)</h3><div<SP>class="items_des"><p>you can buy item here</p><p><span<SP>class="dt">duration</span><span<SP>class="zb_color2">2990</span><span<SP>class="dt">/2990</span></p><div<SP>style="color:#06F917"><p>item 20</p></div></div><div<SP>class="zb_color3">highest level</div></div>&&TXT:

and i tried and failed
iimSet("_DS_ObjectId","event_div");
iimSet("_DS_Command","LDOWN");
iimPlay("DS_Mouse.iim");

so,the correct div id is?
joiner
 
Posts: 8
Joined: Tue Dec 04, 2012 2:42 am

Re: Workaround for lack of DS mouse commands

by davidpoor on Wed Dec 12, 2012 8:44 am

Hello joiner:

Your settings look correct. The issue may be that the web page you are dealing with may not be responding to a mousedown, but may instead be responding to a click or mouseup. I would suggest that you try to first manually experiment with interactions: e.g. hold down the mouse button and see if that triggers the desired event. Then release the mouse button and see what happens. Do note, however, that releasing the mouse button will trigger both a mouseup AND a click.

It is also possible that the web page is actually responding to an element (e.g. an outer div) that contains the "event_div". I would recommend inspecting the element (e.g. with FireBug) and see if you can identify an on..... event in the source code.
davidpoor
 
Posts: 33
Joined: Fri May 23, 2008 1:45 pm

Re: Workaround for lack of DS mouse commands

by highKo on Mon May 26, 2014 12:23 pm

davidpoor wrote: If the target object does not have an id, you will need to modify the macro and use a different technique to select the HTML object.


my element has no ID. i would prefer to click it based on X/Y . Could anyone modify it for this, pleeeease?

In my case DS CLICK is the only method which works, but it would be superb if it would run in my Firefox.
highKo
 
Posts: 3
Joined: Mon Jan 25, 2010 8:06 am

Re: Workaround for lack of DS mouse commands

by chivracq on Mon May 26, 2014 1:59 pm

highKo wrote:
davidpoor wrote: If the target object does not have an id, you will need to modify the macro and use a different technique to select the HTML object.


my element has no ID. i would prefer to click it based on X/Y . Could anyone modify it for this, pleeeease?

In my case DS CLICK is the only method which works, but it would be superb if it would run in my Firefox.

CIM...! :mrgreen:

This Thread is from 2 years ago, 1 year before the EVENT Mode was introduced in iMacros for FF which can handle most Mouse Actions (hum, except Right-Click, or maybe it can but it's not documented and I've never really managed to get the R-Click to work), so, have you tried the EVENT Mode...?
Be more specific otherwise and give more Details, together with your Full Config, with URL of the Page and what exactly you want to achieve...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6479
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Workaround for lack of DS mouse commands

by highKo on Tue May 27, 2014 1:13 am

hi, thanks for your response (y)

VERSION BUILD=8820413 RECORDER=FX , Windows 7, FF 20 (but already testet newer Versions)

I tried all recording methods so far (normal click , TAG, event) but only was succesful with DS Click. (the other worked only on recording, not at playing)

It is for a browser game with a login. here is the relevant part of the source code (so far i am right)

Code: Select all
edit


i really don't get how the form is submitted, because the action flag is blank. i want to click the seconds image input. i already checked the function behind the onclick event, it only returns true or false.
Last edited by highKo on Fri May 30, 2014 4:40 am, edited 1 time in total.
highKo
 
Posts: 3
Joined: Mon Jan 25, 2010 8:06 am

Re: Workaround for lack of DS mouse commands

by chivracq on Tue May 27, 2014 2:55 am

highKo wrote:hi, thanks for your response (y)

VERSION BUILD=8820413 RECORDER=FX , Windows 7, FF 20 (but already testet newer Versions)

I tried all recording methods so far (normal click , TAG, event) but only was succesful with DS Click. (the other worked only on recording, not at playing)

It is for a browser game with a login. here is the relevant part of the source code (so far i am right)

Code: Select all
<script type='text/javascript' src='bar.js'></script>
<form name='form1' method='post' action='' style='margin:0px;'>
<input type='hidden' id='kasa' name='kasa' value='124172938'>
<input type='hidden' id='cena_ultras' name='cena_ultras' value='1440'>
<input type='hidden' id='cena_hools' name='cena_hools' value='5300'>
<br><br>
<table width='90%' border='0' cellspacing='3' cellpadding='3' align='center'>
  <tr>
    <td align='center' width='50%' valign='top'><img src='http://s1.ultrasgame.com/img/game/img_bar/ultras3.jpg' border='0' alt=''><br><b>Edmund</b> bekannt in der ganzen Gegend kann dir für <b>1440</b> &euro;Hools täglich zur Verfügung stehen</td>
    <td align='center'  valign='top'><img src='http://s1.ultrasgame.com/img/game/img_bar/hools2.jpg' border='0' alt=''><br>Du hast eine echt coole Bande, wenn du willst, kann ich sie für <b>5300</b> &euro;Hools täglich verstärken</td>
  </tr>
  <tr>
    <td align='right'><input type='image' name='ultras' value='ultras' src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_off.jpg' border='0' onmouseover="this.src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_on.jpg'" onmouseout="this.src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_off.jpg'" onclick="return bar_test('ultras');"></td>
    <td align='right'><input type='image' name='hools' value='hools' src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_off.jpg' border='0' onmouseover="this.src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_on.jpg'" onmouseout="this.src='http://s1.ultrasgame.com/img/de/game/img_bar/zwerbuj_off.jpg'" onclick="return bar_test('hools');"></td>
  </tr>
  </table>
</form>


i really don't get how the form is submitted, because the action flag is blank. i want to click the seconds image input. i already checked the function behind the onclick event, it only returns true or false.


Ah OK, that's classic (for me now, though the first time I encountered it, it took me weeks to find the Solution...!), you have a MouseOver displaying a different Image than the "real" Image that you want to click on...

You need to record your Macro in Automatic Mode (with or without ID's, as long as you get the Name of the .JPG in the Statement, which will be stg like "..../zwerbuj_on.jpg'" and you manually modify in your Script the "_on.jpg" to "_off.jpg"... (Or the other way round...) Voila...!
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6479
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Workaround for lack of DS mouse commands

by highKo on Tue May 27, 2014 4:26 am

thanks for the tip, I already know and used it in other cases in the game. I can tag the button , I even have a script that can toggle the mouseover and so on. but none of the scripts (except the DS script) can send the form so that it works like I click it by my own. I alreasd tracked the POSTDATA and have a syntax for sending the formular but i dont know where i have to add the "?blala=value&blabla2=value" statement. (so far this works on POST method, I only read about GET method).

As the whim takes you I could give you access via PM so that you can look and feel how the page interacts. I would donate you a beer or a soft drink for a solution ;)
highKo
 
Posts: 3
Joined: Mon Jan 25, 2010 8:06 am


Return to iMacros for Firefox

Who is online

Users browsing this forum: Google [Bot] and 7 guests

-->