How to use click_link method of Capybara.Node.Actions Package

Best Capybara code snippet using Capybara.Node.Actions.click_link

actions.rb

Source:actions.rb Github

copy

Full Screen

...4 module Actions5 ##6 #7 # Finds a button or link and clicks it. See {Capybara::Node::Actions#click_button} and8 # {Capybara::Node::Actions#click_link} for what locator will match against for each type of element9 # @!macro waiting_behavior10 # If the driver is capable of executing JavaScript, +$0+ will wait for a set amount of time11 # and continuously retry finding the element until either the element is found or the time12 # expires. The length of time +find+ will wait is controlled through {Capybara.default_max_wait_time}13 #14 # @option options [false, Numeric] wait (Capybara.default_max_wait_time) Maximum time to wait for matching element to appear.15 #16 # @overload click_link_or_button([locator], options)17 #18 # @param [String] locator See {Capybara::Node::Actions#click_button} and {Capybara::Node::Actions#click_link}19 #20 # @return [Capybara::Node::Element] The element clicked21 #22 def click_link_or_button(locator=nil, options={})23 locator, options = nil, locator if locator.is_a? Hash24 find(:link_or_button, locator, options).click25 end26 alias_method :click_on, :click_link_or_button27 ##28 #29 # Finds a link by id, text or title and clicks it. Also looks at image30 # alt text inside the link.31 #32 # @macro waiting_behavior33 #34 # @overload click_link([locator], options)35 # @param [String] locator text, id, title or nested image's alt attribute36 # @param options See {Capybara::Node::Finders#find_link}37 #38 # @return [Capybara::Node::Element] The element clicked39 def click_link(locator=nil, options={})40 locator, options = nil, locator if locator.is_a? Hash41 find(:link, locator, options).click42 end43 ##44 #45 # Finds a button on the page and clicks it.46 # This can be any \<input> element of type submit, reset, image, button or it can be a47 # \<button> element. All buttons can be found by their id, value, or title. \<button> elements can also be found48 # by their text content, and image \<input> elements by their alt attribute49 #50 # @macro waiting_behavior51 #52 # @overload click_button([locator], options)53 # @param [String] locator Which button to find...

Full Screen

Full Screen

click_link

Using AI Code Generation

copy

Full Screen

1visit('/')2click_link("About")3visit('/')4click_link("About")5visit('/')6click_link("About")7visit('/')8click_link("About")9visit('/')10click_link("About")

Full Screen

Full Screen

click_link

Using AI Code Generation

copy

Full Screen

1 Capybara::Poltergeist::Driver.new(app, js_errors: false)2World(Capybara::DSL)3When(/^I click on the link$/) do4 click_link('Gmail')5Then(/^I should be on the gmail page$/) do6 page.should have_content('Sign in to continue to Gmail')7 Capybara::Poltergeist::Driver.new(app, js_errors: false)8World(Capybara::DSL)9When(/^I click on the link$/) do10 click_link('Gmail')11Then(/^I should be on the gmail page$/) do12 page.should have_content('Sign in to continue to Gmail')

Full Screen

Full Screen

click_link

Using AI Code Generation

copy

Full Screen

1 def search_for(search_term)2 all('.r a')3google.search_for('Capybara')

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Capybara automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful