How to use title method of Selenium.WebDriver.Remote Package

Best Selenium code snippet using Selenium.WebDriver.Remote.title

driver.rb

Source:driver.rb Github

copy

Full Screen

...54 end55 def html56 browser.page_source57 end58 def title59 browser.title60 end61 def current_url62 browser.current_url63 end64 def find_xpath(selector)65 browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }66 end67 def find_css(selector)68 browser.find_elements(:css, selector).map { |node| Capybara::Selenium::Node.new(self, node) }69 end70 def wait?; true; end71 def needs_server?; true; end72 def execute_script(script, *args)73 browser.execute_script(script, *args.map { |arg| arg.is_a?(Capybara::Selenium::Node) ? arg.native : arg} )74 end75 def evaluate_script(script, *args)76 result = execute_script("return #{script}", *args)77 unwrap_script_result(result)78 end79 def evaluate_async_script(script, *args)80 browser.manage.timeouts.script_timeout = Capybara.default_max_wait_time81 result = browser.execute_async_script(script, *args.map { |arg| arg.is_a?(Capybara::Selenium::Node) ? arg.native : arg} )82 unwrap_script_result(result)83 end84 def save_screenshot(path, _options={})85 browser.save_screenshot(path)86 end87 def reset!88 # Use instance variable directly so we avoid starting the browser just to reset the session89 if @browser90 navigated = false91 start_time = Capybara::Helpers.monotonic_time92 begin93 if !navigated94 # Only trigger a navigation if we haven't done it already, otherwise it95 # can trigger an endless series of unload modals96 begin97 @browser.manage.delete_all_cookies98 if options[:clear_session_storage]99 if @browser.respond_to? :session_storage100 @browser.session_storage.clear101 else102 warn "sessionStorage clear requested but is not available for this driver"103 end104 end105 if options[:clear_local_storage]106 if @browser.respond_to? :local_storage107 @browser.local_storage.clear108 else109 warn "localStorage clear requested but is not available for this driver"110 end111 end112 rescue Selenium::WebDriver::Error::UnhandledError113 # delete_all_cookies fails when we've previously gone114 # to about:blank, so we rescue this error and do nothing115 # instead.116 end117 @browser.navigate.to("about:blank")118 end119 navigated = true120 #Ensure the page is empty and trigger an UnhandledAlertError for any modals that appear during unload121 until find_xpath("/html/body/*").empty? do122 raise Capybara::ExpectationNotMet.new('Timed out waiting for Selenium session reset') if (Capybara::Helpers.monotonic_time - start_time) >= 10123 sleep 0.05124 end125 rescue Selenium::WebDriver::Error::UnhandledAlertError, Selenium::WebDriver::Error::UnexpectedAlertOpenError126 # This error is thrown if an unhandled alert is on the page127 # Firefox appears to automatically dismiss this alert, chrome does not128 # We'll try to accept it129 begin130 @browser.switch_to.alert.accept131 sleep 0.25 # allow time for the modal to be handled132 rescue modal_error133 # The alert is now gone - nothing to do134 end135 # try cleaning up the browser again136 retry137 end138 end139 end140 def switch_to_frame(frame)141 case frame142 when :top143 @frame_handles[browser.window_handle] = []144 browser.switch_to.default_content145 when :parent146 # would love to use browser.switch_to.parent_frame here147 # but it has an issue if the current frame is removed from within it148 @frame_handles[browser.window_handle].pop149 browser.switch_to.default_content150 @frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }151 else152 @frame_handles[browser.window_handle] ||= []153 @frame_handles[browser.window_handle] << frame.native154 browser.switch_to.frame(frame.native)155 end156 end157 def current_window_handle158 browser.window_handle159 end160 def window_size(handle)161 within_given_window(handle) do162 size = browser.manage.window.size163 [size.width, size.height]164 end165 end166 def resize_window_to(handle, width, height)167 within_given_window(handle) do168 # Don't set the size if already set - See https://github.com/mozilla/geckodriver/issues/643169 if marionette? && (window_size(handle) == [width, height])170 {}171 else172 browser.manage.window.resize_to(width, height)173 end174 end175 end176 def maximize_window(handle)177 within_given_window(handle) do178 browser.manage.window.maximize179 end180 sleep 0.1 # work around for https://code.google.com/p/selenium/issues/detail?id=7405181 end182 def close_window(handle)183 within_given_window(handle) do184 browser.close185 end186 end187 def window_handles188 browser.window_handles189 end190 def open_new_window191 browser.execute_script('window.open();')192 end193 def switch_to_window(handle)194 browser.switch_to.window handle195 end196 def within_window(locator)197 handle = find_window(locator)198 browser.switch_to.window(handle) { yield }199 end200 def accept_modal(_type, options={})201 yield if block_given?202 modal = find_modal(options)203 modal.send_keys options[:with] if options[:with]204 message = modal.text205 modal.accept206 message207 end208 def dismiss_modal(_type, options={})209 yield if block_given?210 modal = find_modal(options)211 message = modal.text212 modal.dismiss213 message214 end215 def quit216 @browser.quit if @browser217 rescue Selenium::WebDriver::Error::SessionNotCreatedError, Errno::ECONNREFUSED218 # Browser must have already gone219 rescue Selenium::WebDriver::Error::UnknownError => e220 unless silenced_unknown_error_message?(e.message) # Most likely already gone221 # probably already gone but not sure - so warn222 warn "Ignoring Selenium UnknownError during driver quit: #{e.message}"223 end224 ensure225 @browser = nil226 end227 def invalid_element_errors228 [::Selenium::WebDriver::Error::StaleElementReferenceError,229 ::Selenium::WebDriver::Error::UnhandledError,230 ::Selenium::WebDriver::Error::ElementNotVisibleError,231 ::Selenium::WebDriver::Error::InvalidSelectorError, # Work around a race condition that can occur with chromedriver and #go_back/#go_forward232 ::Selenium::WebDriver::Error::ElementNotInteractableError,233 ::Selenium::WebDriver::Error::ElementClickInterceptedError,234 ::Selenium::WebDriver::Error::InvalidElementStateError,235 ::Selenium::WebDriver::Error::ElementNotSelectableError,236 ]237 end238 def no_such_window_error239 Selenium::WebDriver::Error::NoSuchWindowError240 end241 # @api private242 def marionette?243 firefox? && browser && @w3c244 end245 # @api private246 def firefox?247 browser_name == "firefox"248 end249 # @api private250 def chrome?251 browser_name == "chrome"252 end253 # @deprecated This method is being removed254 def browser_initialized?255 super && !@browser.nil?256 end257 private258 # @api private259 def browser_name260 options[:browser].to_s261 end262 def modal_error263 if defined?(Selenium::WebDriver::Error::NoSuchAlertError)264 Selenium::WebDriver::Error::NoSuchAlertError265 else266 Selenium::WebDriver::Error::NoAlertPresentError267 end268 end269 def find_window(locator)270 handles = browser.window_handles271 return locator if handles.include? locator272 original_handle = browser.window_handle273 handles.each do |handle|274 switch_to_window(handle)275 if (locator == browser.execute_script("return window.name") ||276 browser.title.include?(locator) ||277 browser.current_url.include?(locator))278 switch_to_window(original_handle)279 return handle280 end281 end282 raise Capybara::ElementNotFound, "Could not find a window identified by #{locator}"283 end284 def insert_modal_handlers(accept, response_text)285 prompt_response = if accept286 if response_text.nil?287 "default_text"288 else289 "'#{response_text.gsub("\\", "\\\\\\").gsub("'", "\\\\'")}'"290 end...

Full Screen

Full Screen

spec_helper.rb

Source:spec_helper.rb Github

copy

Full Screen

...4 class Driver5 attr_reader :driver6 BROWSERS = ['firefox', 'chrome', 'internet_explorer', 'opera']7 OSES = ['XP', 'VISTA', 'LINUX']8 def initialize(title)9 @title = title10 @environment = ENV['ENVIRONMENT'] || 'gamma'11 @browser = ENV['BROWSER'] || 'chrome'12 raise "BROWSER must be one of #{BROWSERS.join(', ')}" unless BROWSERS.include?(@browser.to_s)13 @version = ENV['VERSION'] || '13'14 @os = ENV['OS'] || :XP15 raise "OS must be one of #{OSES.join(', ')}" unless OSES.include?(@os.to_s)16 @driver = if ENV['TEST_ENV'] == 'local'17 local_driver18 elsif ENV['TEST_ENV'] == 'iphone4'19 iphone4_driver20 elsif ENV['TEST_ENV'] == 'iphone5'21 iphone5_driver22 elsif ENV['TEST_ENV'] == 'iphone6'23 iphone6_driver24 elsif ENV['TEST_ENV'] == 'ipad4'25 ipad4_driver26 elsif ENV['TEST_ENV'] == 'ipad5'27 ipad5_driver28 elsif ENV['TEST_ENV'] == 'ipad6'29 ipad6_driver30 elsif ENV['TEST_ENV'] == 'android'31 android_driver32 else33 saucelabs_driver34 end35 end36 def local_driver37 Selenium::WebDriver.for(@browser.to_sym)38 end39 def iphone4_driver40 caps = Selenium::WebDriver::Remote::Capabilities.iphone41 caps.platform = 'Mac 10.6'42 caps.version = '4.3'43 Selenium::WebDriver.for(44 :remote,45 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',46 :desired_capabilities => caps)47 end48 def iphone5_driver49 caps = Selenium::WebDriver::Remote::Capabilities.iphone50 caps.platform = 'Mac 10.8'51 caps.version = '5.1'52 Selenium::WebDriver.for(53 :remote,54 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',55 :desired_capabilities => caps)56 end57 def iphone6_driver58 caps = Selenium::WebDriver::Remote::Capabilities.iphone59 caps.platform = 'Mac 10.8'60 caps.version = '6'61 Selenium::WebDriver.for(62 :remote,63 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',64 :desired_capabilities => caps)65 end66 def ipad4_driver67 caps = Selenium::WebDriver::Remote::Capabilities.ipad68 caps.platform = 'Mac 10.6'69 caps.version = '4.3'70 Selenium::WebDriver.for(71 :remote,72 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',73 :desired_capabilities => caps)74 end75 def ipad5_driver76 caps = Selenium::WebDriver::Remote::Capabilities.ipad77 caps.platform = 'Mac 10.8'78 caps.version = '5.1'79 Selenium::WebDriver.for(80 :remote,81 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',82 :desired_capabilities => caps)83 end84 def ipad6_driver85 caps = Selenium::WebDriver::Remote::Capabilities.ipad86 caps.platform = 'Mac 10.8'87 caps.version = '6'88 Selenium::WebDriver.for(89 :remote,90 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',91 :desired_capabilities => caps)92 end93 def android_driver94 caps = Selenium::WebDriver::Remote::Capabilities.android95 caps.platform = 'Linux'96 caps.version = '4'97 Selenium::WebDriver.for(98 :remote,99 :url => 'http://#YOURSAUCEKEYHERE@ondemand.saucelabs.com:80/wd/hub',100 :desired_capabilities => caps)101 end102 def saucelabs_driver103 caps = Selenium::WebDriver::Remote::Capabilities.send(@browser.to_sym)104 caps.version = @version unless @browser.to_s == 'chrome'105 caps.platform = @os106 caps[:name] = @title || 'BR Selenium Ruby and Sauce Test'107 Selenium::WebDriver.for(108 :remote,109 :url => 'http://cloudbees_bleacher:b3af4895-9684-4c75-8211-246d26fb7183@ondemand.saucelabs.com:80/wd/hub',110 :desired_capabilities => caps)111 end112 def goto(url)113 if url.include?("?")114 url = "#{url}&ads=0&skins=0"115 else116 url = "#{url}?ads=0&skins=0"117 end118 if @environment == 'alpha'119 @driver.navigate.to "#YOURURLHERE"+url120 elsif @environment == 'beta'121 @driver.navigate.to "#YOURURLHERE"+url122 elsif @environment == 'gamma'123 @driver.navigate.to "#YOURURLHERE"+url124 elsif @environment == 'delta'125 @driver.navigate.to "#YOURURLHERE"+url126 else127 @driver.navigate.to "#YOURURLHERE"+url128 end129 end130 def hover(type, selector, options = {})131 # Get element to mouse over132 e = @driver.find_element(type, selector)133 # Use Javascript to mouseover134 @driver.execute_script("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}", e)135 # Do extra stuff given by the block136 yield e if block_given?137 begin138 # Mouse out using Javascript139 @driver.execute_script("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseout', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseout');}", e)140 rescue141 end142 end143 def login(email, password)144 title = @driver.title145 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds146 wait.until { @driver.find_element(:id => "log_in_link") }147 @driver.find_element(:id, 'log_in_link').click148 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds149 wait.until { @driver.find_element(:id => "login_button") }150 element = @driver.find_element(:id, 'hat_log_in_email')151 element.send_keys(email)152 element = @driver.find_element(:id, 'hat_log_in_password')153 element.send_keys(password)154 element.submit155 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds156 wait.until { @driver.find_element(:css => "span.user-full-name") }157 end158 def logout159 @driver.find_element(:css, 'span.user-full-name').click160 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds161 wait.until { @driver.find_element(:link => "Logout") }162 @driver.find_element(:link, 'Logout').click163 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds164 wait.until { @driver.find_element(:id => "log_in_link") }165 end166 def login_facebook(email, password)167 title = @driver.title168 @driver.find_element(:id, 'email').send_keys(email)169 element = @driver.find_element(:id, 'pass')170 element.send_keys(password)171 element.submit172 end173 ### Adds a photo to an article / slideshow etc. that is in progress ###174 def add_media(tag)175 @driver.find_element(:link, 'Add Photo').click176 wait = Selenium::WebDriver::Wait.new(:timeout => 30) # seconds177 wait.until { @driver.find_element(:id => "image-search-button") }178 # Type 'tag' into search module179 @driver.find_element(:id, 'image-search-input').send_keys(tag)180 @driver.find_element(:id, 'image-search-button').click181 # wait for picture to show up, then click top left picture...

Full Screen

Full Screen

launchbrowser.rb

Source:launchbrowser.rb Github

copy

Full Screen

...20sleep(5)21element1=driver.find_element :xpath,'//a[@href="https://www.geeksforgeeks.org/ruby-programming-language/"]'22element1.click()23sleep(5)24title=driver.title25puts "Page tile is "+title26text1=driver.find_element(:class,'entry-title').text27puts "Captured Test is..."+text1...

Full Screen

Full Screen

android_galaxy_s33.rb

Source:android_galaxy_s33.rb Github

copy

Full Screen

...30driver.navigate.to loc131#driver.scroll.to [0, 300]32#driver.goto loc133sleep 534driver.save_screenshot driver.title<<"_galaxyS3_landscape.png"35puts "8 to add"36sleep 837driver.save_screenshot driver.title<<"_galaxyS31_landscape.png"38puts "8 to add"39sleep 840driver.save_screenshot driver.title<<"_galaxyS32_landscape.png"41#driver.scroll.to [100, 0]42 43sleep 144end...

Full Screen

Full Screen

oral_art_search_s3.rb

Source:oral_art_search_s3.rb Github

copy

Full Screen

...30driver.navigate.to loc131#driver.scroll.to [0, 300]32#driver.goto loc133sleep 534driver.save_screenshot driver.title<<"_galaxyS3_portait.png"35puts "5 to Rotate"36sleep 537driver.save_screenshot driver.title<<"_galaxyS3_landscape.png"38#driver.scroll.to [100, 0]39 40sleep 141end

Full Screen

Full Screen

example.rb

Source:example.rb Github

copy

Full Screen

...31 teardown32end33run do34 @driver.get 'http://the-internet.herokuapp.com'35 expect(@driver.title.include?('The Internet')).to eql true36end...

Full Screen

Full Screen

android555.rb

Source:android555.rb Github

copy

Full Screen

...25#driver.goto loc126puts "I'm about to go to URL "27sleep 528driver.navigate.to "http://author.oralb.pgsitecore.com"29driver.save_screenshot driver.title<<"_galaxyS3_landscape.png"30#driver.scroll.to [100, 0]31browser.a(:class =>'nav-open-btn').when_present.click32 33sleep 234driver.save_screenshot driver.title<<"_galaxyS3_landscape.png"...

Full Screen

Full Screen

grid.rb

Source:grid.rb Github

copy

Full Screen

2require 'selenium-webdriver'3require 'rspec/expectations'4include RSpec::Matchers5capabilities = [ Selenium::WebDriver::Remote::Capabilities.firefox, Selenium::WebDriver::Remote::Capabilities.chrome, Selenium::WebDriver::Remote::Capabilities.phantomjs]6title = 'LedgerSMB 1.6.0-dev'7def setup(capability='firefox')8 @driver = Selenium::WebDriver.for(9 :remote,10 :url => 'http://grid-server:4422/wd/hub',11 :desired_capabilities => capability) # you can also use :chrome, :safari, etc.12end13def teardown14 @driver.quit15end16def run(capability)17 setup(capability)18 yield19 teardown20end21for capability in capabilities22 run(capability) do23 @driver.get 'http://ledgersmb-vm:5000/login.pl'24 expect(@driver.title).to eq(title)25 puts (capability.browser_name + ': ' + (@driver.title == title ? 'Ok' : 'Failed'))26 end27end...

Full Screen

Full Screen

title

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2elements = driver.find_elements(:tag_name, 'a')3 puts e.attribute('href')

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful