From: "Mattias A." Date: 2012-12-05T13:58:10+09:00 Subject: Re: selenium-webdriver + puts page title Mattias A. wrote in post #1087838: > unknown wrote in post #1087829: >> Am 04.12.2012 20:19, schrieb Mattias A.: >>> ------------------- >>> I did a new try with below but it insists on running the method by_id >>> even if i not call it? Any ides? >> >> I do not think it does. Try including statements like >> "puts 'method by_id'" and "puts 'method by_name'" >> in the respective method. > When I removed the space in def by_id it passed, it dident run the code > due to the syntax error in this method. (as i understands it) > >> >>> #By ID - driver.find_element(:id,) >>> @driver.find_element (:id, "q") >> >> You should remove the space before the argument parentheses >> (it causes an error in Ruby 1.9.3). >> >> @driver.find_element(:id, "q") > > Thanks for your help, now it works! :D ----- Hi again, this is maybe a better way to do it? When you should test if the element are available or not? Or how should you solve it? require 'selenium-webdriver' class Find_element def initialize @driver = Selenium::WebDriver.for :firefox @driver.get "http://google.com" end def page_title if @driver.title puts "Page title found: #{@driver.title}" else puts "Page title not found" end end def by_id #By ID - driver.find_element(:id,) if @driver.find_element(:id, "gbqfba") puts 'Did find element with Id: gbqfba' else puts 'Did not find element with id gbqfba' end end def by_name #By name - driver.find_element(:name,) if @driver.find_element(:name, "q") puts 'Did find element with Name: q' else puts 'Did not find element with Name: q' end end end test = Find_element.new test.by_id test.by_name test.page_title -- Posted via http://www.ruby-forum.com/.