vendredi 18 mai 2018

Unable to click the rating image via capybara using selenium-cucumber

This is the below html code. When the mouse hovered over the star images the image source turn to star-on.png. If you see the below code it means i gave two star rating.

<div id="user_rating" class="rating" style="cursor: pointer; width: 100px;">
<img src="/assets/jquery.raty/star-on.png" alt="1" title="">&nbsp;
<img src="/assets/jquery.raty/star-on.png" alt="2" title="">&nbsp;
<img src="/assets/jquery.raty/star-off.png" alt="3" title="">&nbsp;
<img src="/assets/jquery.raty/star-off.png" alt="4" title="">&nbsp;
<img src="/assets/jquery.raty/star-off.png" alt="5" title="">
<input type="hidden" name="score"></div>

I tried the following code in the cucumber using the img src, all and values but I am not able to click the rating images

img_src passed as "/assets/jquery.raty/star-off.png"

Then /^I click on the image with src "([^\"]*)"$/ do |img_src|
   find("img[src=\'#{img_src}\']", match: :prefer_exact).click
end

alt_text is passed as "3"

Then /^I click on the image with alt "([^\"]*)"$/ do |alt_text|
  page.execute_script %Q[jQuery("img[alt=\'{alt_text}\']").first().mouseenter();]
  page.execute_script %Q[jQuery("img[alt=\'#{alt_text}\']").first().click();]
end

selector = proper xpath is passed

And /^I click by xpath "([^\"]*)"$/ do |selector|
  find(:xpath, selector, visible: true, match: :first).click
end

Can some one let me know a proper selenium command to click the rating

Aucun commentaire:

Enregistrer un commentaire