Auto Clicking Images

in Script development
Subscribe to Auto Clicking Images 7 posts, 4 voices



Dolomite13 Scriptwright

So i figured out how to identify an "Input" element and click it with .click() but now I have an image that I want to simulate a click on and can't seem to figure out how to make that happen.

I can't call out the image by ID so I am currently parsing the whole page and getting back a list of elements I can search for the image name I want. I get the position of the one I want to click and try the .click() on it and nothing happens. In the example below I am trying to simply click the last one that is valid.


cix = document.getElementsByTagName("img");
cixx = cix.length
comploop = 0;
for (q=0; q<cixx>
if (cix[q].src.search("Buff.png")!=-1) {
comploop = q }
}
cix[comploop].click();

This is and example of the image tag ...

<img clickrewriteurl="http://ta.wizapps.voxel.wizards.com/_buffPlayer.php" clickrewriteform="formfriendid3826" 
clickrewriteid="friendid3826" clicktohide="showfriendid3826" 
clicktoshow="waitfriendid3826" style="cursor: pointer; vertical-align: middle; padding-right: 4px;"
src="http://2974.voxcdn.com/ta/WebGraphics/Buttons/Buff.png" 
onclick='var self = this;FBML.clickRewriteAjax("23415053320", true, "app23415053320_friendid3826", "http:\/
\/ta.wizapps.voxel.wizards.com\/_buffPlayer.php", "app23415053320_formfriendid3826", null);FBML.clickToHide
("app23415053320_showfriendid3826");FBML.clickToShow("app23415053320_waitfriendid3826");return false;'>

Does anyone know of any way that I can have the script actually simulate a click on this image for me?

Any help would be appreciated.

Thanx

MJ

 
JoeSimmons Scriptwright

First of all... that long procedure for finding Buff.png is not needed and can be summed up in one line.

var buff = document.evaluate("//img[contains(@src, 'Buff.png')]", document, null, 9, null).singleNodeValue;

Then you can use this (I think so - untested)
buff.onclick();

 
Dolomite13 Scriptwright

Hmmm... not working ...

Perhapse I should create a link that runs this from a function rather than trying to run it with the page load... I will play around with it this evening.

Thanx for the help though I appreciate it =)

M

 
Dolomite13 Scriptwright

Well embedding it as a function and using a click to activate the function didnt work either. :(

 
znerp Scriptwright

Once you have the element, look at the links in this topic for some help on clicking it.

 
Avindra V.G. Scriptwright

If there is an active event listener, you can "click it" with:

unsafeWindow.document.evaluate("//img[contains(@src, 'Buff.png')]", document, null, 9, null).singleNodeValue.onclick()

Otherwise, it'll be a bit more complicated than that.

 
Dolomite13 Scriptwright

I found the solution. I get the element I want to click and then use the following code instead of the .click()

I have several I want to click with a delay between each and that was alot harder to implement than I thought but setTimeout and cookies are my friends and they helped alot =)

Thanx


 		var evt = document.createEvent('MouseEvents'); 
 		evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); 
 		var ch = element; 
 		var canceled = !ch.dispatchEvent(evt); 


Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel