Avijit Majhi
Avijit Majhi

Reputation: 518

How to perform click event on SVG element in Capybara

Hi I am new to Capybara and selenium.I am using gem 'capybara' and gem 'selenium-webdriver'.I have a view where I have to click on an icon.The html of the view is

<svg class="assign-job icon icon-box-outgoing" ng-click="something">
   <use xlink:href="#icon-box-outgoing"></use>
</svg>

I want to perform click event onto this element.I have also tried using xpath but that didn't work.I have attached a screenshot please find that.enter image description here

Upvotes: 1

Views: 1974

Answers (2)

mgharikrishnan
mgharikrishnan

Reputation: 1

You can use xpath to identify the element.

//div[@class='jobActionsDisplayDeterminer']/*[name()='svg']/*[name()='use'][@xlink:href='#icon-box-outgoing']

Upvotes: 0

Florent B.
Florent B.

Reputation: 42528

You can use a CSS selector to click on the svg element:

find(:css, "svg.assign-job.icon-box-outgoing").click

or to click on the use element:

find(:css, "use[href='#icon-box-outgoing']").click

Upvotes: 4

Related Questions