How to Click Text/Numbers Using Capybara and Cucumber

Problems:

We have a jquery date picker calendar. Now, we have to open the calendar and select a date. But selecting a link and selecting a date (number) is different.

Screen Shot 2015-11-22 at 2.17.17 PM

Issues to be discussed:

Cucumber contains a web step that allows you to easily click a link. But what if what you want to click is not a link, but some plain text like:



<h3 class='clickable-text'>Click me</h3>


Cucumber doesn’t have a web step for such case. so I needed an alternative approach. Capybara code that would click the text above.

find('.clickable-text', :text => 'Click me').click

Then I’ve got a cool idea. Let’s load them up…

Solutions:

Save the file at auto_posting.rb

And I want to make schedule posting with custom time and date

Given /^I want to make schedule posting with custom time and date$/ do
 find(:xpath, ".//*[@id='SocialHistory']").click
 find(:xpath, ".//*[@id='SocialDate']").click
 page.execute_script %Q{ $("input[id^='splash_']:contains('28')").trigger("click"); }
end

Save the file at auto_posting.feature

 

I needed to set custom date and so I refectored thus  I can bypass my date 29.

And I select 29 from the calender.

Given /^I select "([^"]*)" from the calender$/ do |date|
 find('.calendarDate', :text => date).click
end

Thanks a lot to automicobject and teamgaslight and gazler for the comments.