3

I have written following lines to click all links in fetched page but it clicks on one link only and stuck there clicking , I have used Selenium Web Driver API:

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get " http://www.testfire.net "
for i in 1..100
    link = driver.find_element(:tag_name, "a")
    link.click
end

tell me how can I skip clicked link and go to next one or can set the range from 1 to until it reaches end of html page at </html> tag. I think it would be like eofpage = drive.find_element(:tag_name, "/html")

2 Answers 2

4

It looks like there is a driver.find_elements method:

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get " http://www.testfire.net "

driver.find_elements(:tag_name, "a").each {|link| link.click }
Sign up to request clarification or add additional context in comments.

Comments

1

we can use bellow code to find the all links in a page and open with new tab.

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome
@driver.get "http://thiyagarajan.wordpress.com/"
  link = @driver.find_elements(:tag_name, "a")
  link.each do |a|
    a = @driver.execute_script("var d=document,a=d.createElement('a');a.target='_blank';a.href=arguments[0];a.innerHTML='.';d.body.appendChild(a);return a", a)
    a.click
  end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.