0

i am getting this error by using answer 1I want to find a link on a local page and then click on it. Right now I am successful in finding a particular link (because there are many links with the same class), but I am unable to click on it. Here is my code:

# encoding: utf-8    
require 'rubygems'
require 'watir-webdriver'
require 'json'
require 'sqlite3'
require 'haml'
require 'data_mapper'
require 'open-uri'
require 'nokogiri'
require 'pp'
require 'mysql'
require 'dbi'
require 'mechanize'

page_html = Nokogiri::HTML(open("My Library   book.com.htm"))
page_html.css("div.adbl-lib-content
table")[0].css('tbody').css('tr')[8].css('td')[9].css('div').css('a')

and I am getting this result:

<a style="color: #FFF; font-family: Arial; font-size: 11px; font-weight: bold; background-color: #333333; padding: 2px 8px;" title="Click to download" class="adbl-download-it" href="#">DOWNLOAD</a>

How can I click this link?

Ahsan aslam
  • 1,149
  • 2
  • 16
  • 35

1 Answers1

1

I believe you have to use the page object by Mechanize. You can then build the link object manually and call click on it:

mechanize = Mechanize.new
page = mechanize.get "book.com.htm"
link_node = page.css("div.adbl-lib-content
table")[0].css('tbody').css('tr')[8].css('td')[9].css('div').css('a')

Mechanize::Page::Link.new(link_node, mechanize, page).click
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168