# Invoke javascript by clicking an image

**URL:** <https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155>\
**Category:** Ruby\
**Created:** [January 6, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155 "2010-01-06T14:51:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![techie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@techie](https://www.ruby-forum.com/u/techie)\
**Post date:** [January 6, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155/1 "2010-01-06T14:51:03Z")

</div>

I am newbie to Ruby so pl pardon my ignorance.

I have an image in a web page which has the following code:

\<img style = “cursor: hand”,  
onclick="javascript:fnC20WebCtrlOpenCtrlChangeProjectWindow(this,event,3,0,‘1022’,’’);

Can someone please suggest how to click this image (basically, invoke  
the javascript) using Ruby?? Tried searching the net but hadn’t had much  
luck.

---

<div class="post-metadata">

**Author:** ![techie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@techie](https://www.ruby-forum.com/u/techie)\
**Post date:** [January 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155/2 "2010-01-06T16:39:39Z")

</div>

Go Ma wrote:

> I am newbie to Ruby so pl pardon my ignorance.
> 
> I have an image in a web page which has the following code:
> 
> \<img style = “cursor: hand”,  
> onclick="javascript:fnC20WebCtrlOpenCtrlChangeProjectWindow(this,event,3,0,‘1022’,‘’);
> 
> Can someone please suggest how to click this image (basically, invoke  
> the javascript) using Ruby?? Tried searching the net but hadn’t had much  
> luck.

If you want to control a browser programatically using Ruby, have a look  
at Watir: [http://watir.com/](http://watir.com/)

Another option is Selenium.

---

<div class="post-metadata">

**Author:** ![techie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@techie](https://www.ruby-forum.com/u/techie)\
**Post date:** [January 6, 2010, 9:12pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155/3 "2010-01-06T21:12:29Z")

</div>

On Wednesday 06 January 2010 10:33:47 am Go Ma wrote:

> I am attaching the relevant code I  
> could view using IEDev bar.

Wait, why are you attaching this as a screenshot? Shouldn’t you be able  
to  
just provide source, as text? Or better yet, a URL to the page in  
question?

Better still, give us a simplified example – a small HTML page that  
does  
nothing other than demonstrate the problem.

[http://www.catb.org/~esr/faqs/smart-questions.html#volume](http://www.catb.org/~esr/faqs/smart-questions.html#volume)

> [http://www.ruby-forum.com/attachment/4357/screenshot.docx](http://www.ruby-forum.com/attachment/4357/screenshot.docx)

Screenshot… docx. You do realize those don’t go together, don’t you?  
If it’s  
an image, attach an image – png, jpeg, even bmp would work. Not all of  
us  
have (or want) MS Word.

[http://www.catb.org/~esr/faqs/smart-questions.html#formats](http://www.catb.org/~esr/faqs/smart-questions.html#formats)

---

<div class="post-metadata">

**Author:** ![techie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@techie](https://www.ruby-forum.com/u/techie)\
**Post date:** [January 6, 2010, 5:33pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155/4 "2010-01-06T17:33:46Z")

</div>

Hi Brian,

Thanks a lot for your prompt note. I actually started off with Watir,  
but got stuck with the above issue. I am attaching the relevant code I  
could view using IEDev bar. Any help would be appreciated!!

cheers,  
GM

---

<div class="post-metadata">

**Author:** ![techie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@techie](https://www.ruby-forum.com/u/techie)\
**Post date:** [January 6, 2010, 10:48pm UTC](https://www.ruby-forum.com/t/invoke-javascript-by-clicking-an-image/181155/5 "2010-01-06T22:48:03Z")

</div>

Go Ma wrote:

> Thanks a lot for your prompt note. I actually started off with Watir,  
> but got stuck with the above issue.

Then your question should be: “in Watir, how do I click on an image that  
has a javascript onclick handler?”

That question would be best directed to a Watir forum. I also suggest  
that you will get a better answer there if you post the ruby code that  
you already tried but failed. Also show what relevant items you found in  
the Watir documentation and/or source code and/or from googling, and why  
it didn’t help you solve the problem.

> I am attaching the relevant code I  
> could view using IEDev bar. Any help would be appreciated!!

You didn’t paste any code (Ruby or JS) whatsoever. You pasted a document  
containing a screenshot of some HTML.

I _was_ able to open that docx file with OpenOffice, but you should be  
aware that if you make life difficult for the people you are asking for  
help, then they’re not going to be inclined to.

However, I am not a Watir expert anyway, so the best I can offer is to  
try again in a Watir forum.
