yasar
yasar

Reputation: 13768

Clicking group of links in watir

I am new to ruby, and I am trying to work with watir. I think I got the basics, but I am having trouble clicking all links whose id matches a regex. I tried this;

require "watir-webdriver"
browser = Watir::Browser.new :ff
browser.goto "http://mysite.com"
browser.links(:id, /asd[0-7]/).each do |adv|
    adv.click
    sleep 1
end

But it doesn't seem to be clicking the links. I am doing something wrong here? Links are opening in new windows, so looping through them is no problem. But I couldn't make the loop work.

Upvotes: 0

Views: 727

Answers (1)

Dave McNulla
Dave McNulla

Reputation: 2016

This kind of investigation is better in IRB. Anyway, you should validate that you have links to click.

require "watir-webdriver"
browser = Watir::Browser.new :ff
browser.goto "https://rvm.io/"
links = browser.links(:href => /gemsets/)
links.count

I changed mine up to use a site I can access and has links.

Upvotes: 1

Related Questions