user1047912
user1047912

Reputation:

watir-webdriver click on image

Folks,

I have an image with the following HTML code:

<div unselectable="on" class="x-grid-cell-inner x-unselectable" style="; text-align: right;" id="ext-gen1453">
<img alt=""src="data:image/gif;base64,FRFRFR/GFFFFFFFFFF==" class="x-action-col-icon x-action-col-0 folder-action-add folder-action" data-qtip="Add New Music File" id="ext-gen1300">

When I click on the image it should open a pop up so that I can add new music file, I tried a few things but I am not able to click on that image. Any suggestions?

Thanks a lot

Upvotes: 0

Views: 3528

Answers (2)

Dave McNulla
Dave McNulla

Reputation: 2016

You can click on it by the class or a partial match of the class.

@browser.image(:class=>/folder-action-add folder-action/).click

Here is a list of the identifiers you can use for watir, I think it's mostly the same for watir-webdriver.

Upvotes: 2

Jon M
Jon M

Reputation: 11705

So far, you haven't got a consistent way of actually identifying the element. From what you've said in the comments, you've tried the 'text' attribute which doesn't exist, and the 'id' attribute which is auto generated and different every time.

You need to find a way of consistently identifying the element. It's usually preferable to use a semantic class on the element to make styling and testing easier and less brittle. You have a few classes declared, perhaps 'folder-action-add' expresses the intent of the button clearly? If not, you could add one such as 'add-music-file'.

Then you should be able to use watir to select an element by it's class, I'm not familiar with the syntax but at a guess, @browser.image(:class => 'add-music-file') might do the job.

Upvotes: 0

Related Questions