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

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

driver.rb

Source:driver.rb Github

copy

Full Screen

...43 end44 def visit(path)45 browser.navigate.to(path)46 end47 def go_back48 browser.navigate.back49 end50 def go_forward51 browser.navigate.forward52 end53 def html54 browser.page_source55 end56 def title57 browser.title58 end59 def current_url60 browser.current_url61 end62 def find_xpath(selector)63 browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }64 end65 def find_css(selector)66 browser.find_elements(:css, selector).map { |node| Capybara::Selenium::Node.new(self, node) }67 end68 def wait?; true; end69 def needs_server?; true; end70 def execute_script(script, *args)71 browser.execute_script(script, *args.map { |arg| arg.is_a?(Capybara::Selenium::Node) ? arg.native : arg} )72 end73 def evaluate_script(script, *args)74 result = execute_script("return #{script}", *args)75 unwrap_script_result(result)76 end77 def save_screenshot(path, _options={})78 browser.save_screenshot(path)79 end80 def reset!81 # Use instance variable directly so we avoid starting the browser just to reset the session82 if @browser83 navigated = false84 start_time = Capybara::Helpers.monotonic_time85 begin86 if !navigated87 # Only trigger a navigation if we haven't done it already, otherwise it88 # can trigger an endless series of unload modals89 begin90 @browser.manage.delete_all_cookies91 if options[:clear_session_storage]92 if @browser.respond_to? :session_storage93 @browser.session_storage.clear94 else95 warn "sessionStorage clear requested but is not available for this driver"96 end97 end98 if options[:clear_local_storage]99 if @browser.respond_to? :local_storage100 @browser.local_storage.clear101 else102 warn "localStorage clear requested but is not available for this driver"103 end104 end105 rescue Selenium::WebDriver::Error::UnhandledError106 # delete_all_cookies fails when we've previously gone107 # to about:blank, so we rescue this error and do nothing108 # instead.109 end110 @browser.navigate.to("about:blank")111 end112 navigated = true113 #Ensure the page is empty and trigger an UnhandledAlertError for any modals that appear during unload114 until find_xpath("/html/body/*").empty? do115 raise Capybara::ExpectationNotMet.new('Timed out waiting for Selenium session reset') if (Capybara::Helpers.monotonic_time - start_time) >= 10116 sleep 0.05117 end118 rescue Selenium::WebDriver::Error::UnhandledAlertError119 # This error is thrown if an unhandled alert is on the page120 # Firefox appears to automatically dismiss this alert, chrome does not121 # We'll try to accept it122 begin123 @browser.switch_to.alert.accept124 sleep 0.25 # allow time for the modal to be handled125 rescue Selenium::WebDriver::Error::NoAlertPresentError126 # The alert is now gone - nothing to do127 end128 # try cleaning up the browser again129 retry130 end131 end132 end133 def switch_to_frame(frame)134 case frame135 when :top136 @frame_handles[browser.window_handle] = []137 browser.switch_to.default_content138 when :parent139 # would love to use browser.switch_to.parent_frame here140 # but it has an issue if the current frame is removed from within it141 @frame_handles[browser.window_handle].pop142 browser.switch_to.default_content143 @frame_handles[browser.window_handle].each { |fh| browser.switch_to.frame(fh) }144 else145 @frame_handles[browser.window_handle] ||= []146 @frame_handles[browser.window_handle] << frame.native147 browser.switch_to.frame(frame.native)148 end149 end150 def current_window_handle151 browser.window_handle152 end153 def window_size(handle)154 within_given_window(handle) do155 size = browser.manage.window.size156 [size.width, size.height]157 end158 end159 def resize_window_to(handle, width, height)160 within_given_window(handle) do161 browser.manage.window.resize_to(width, height)162 end163 end164 def maximize_window(handle)165 within_given_window(handle) do166 browser.manage.window.maximize167 end168 sleep 0.1 # work around for https://code.google.com/p/selenium/issues/detail?id=7405169 end170 def close_window(handle)171 within_given_window(handle) do172 browser.close173 end174 end175 def window_handles176 browser.window_handles177 end178 def open_new_window179 browser.execute_script('window.open();')180 end181 def switch_to_window(handle)182 browser.switch_to.window handle183 end184 def within_window(locator)185 handle = find_window(locator)186 browser.switch_to.window(handle) { yield }187 end188 def accept_modal(_type, options={})189 yield if block_given?190 modal = find_modal(options)191 modal.send_keys options[:with] if options[:with]192 message = modal.text193 modal.accept194 message195 end196 def dismiss_modal(_type, options={})197 yield if block_given?198 modal = find_modal(options)199 message = modal.text200 modal.dismiss201 message202 end203 def quit204 @browser.quit if @browser205 rescue Errno::ECONNREFUSED206 # Browser must have already gone207 rescue Selenium::WebDriver::Error::UnknownError => e208 unless silenced_unknown_error_message?(e.message) # Most likely already gone209 # probably already gone but not sure - so warn210 warn "Ignoring Selenium UnknownError during driver quit: #{e.message}"211 end212 ensure213 @browser = nil214 end215 def invalid_element_errors216 [Selenium::WebDriver::Error::StaleElementReferenceError,217 Selenium::WebDriver::Error::UnhandledError,218 Selenium::WebDriver::Error::ElementNotVisibleError,219 Selenium::WebDriver::Error::InvalidSelectorError] # Work around a race condition that can occur with chromedriver and #go_back/#go_forward220 end221 def no_such_window_error222 Selenium::WebDriver::Error::NoSuchWindowError223 end224 # @api private225 def find_window(locator)226 handles = browser.window_handles227 return locator if handles.include? locator228 original_handle = browser.window_handle229 handles.each do |handle|230 switch_to_window(handle)231 if (locator == browser.execute_script("return window.name") ||232 browser.title.include?(locator) ||233 browser.current_url.include?(locator))...

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