Estos métodos permiten a la aplicación navegar usando links o botones:
click_link_or_button
click_on
click_link
Tenemos estos fichero HTML:
[~/sinatra/sinatra-selenium/intro(gh-pages)]$ cat index.html <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <ul> <li><a href="simple_link.html" id="example1">simple_link.html</a></li> </ul> </body> </html>
y este otro:
[~/sinatra/sinatra-selenium/intro(gh-pages)]$ cat simple_link.html <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="main"> <div class="section"> <a id="myanchor" title="myanchortitle" href="#">Click this Anchor</a> </div> </div> </body> </html>El siguiente programa visita
index.html
clickea en el link y
visita la segunda página volcando sus resultados:
[~/sinatra/sinatra-selenium/intro(gh-pages)]$ cat check_click.rb require 'capybara' require 'capybara/poltergeist' Capybara.default_driver = :poltergeist session = Capybara::Session.new(:poltergeist) session.visit "http://crguezl.github.io/selenium-examples/index.html" session.click_link "example1" puts session.body # dump the contents of the page session.save_page('example1_download.html')El funcionamiento sería el mismo si usaramos
click_on
o click_link_or_button
.
id
attribute of the anchor, button, or input tag
title
attribute of the anchor, button, or input tag
Text
within the anchor, button, or input tag
value
attribute of the input element where its type is one of
button
,
reset
,
submit
, or
image
alt
attribute where an image is used as an anchor or input
Casiano Rodriguez León 2015-01-07