@@ -37,17 +37,29 @@ def self.for_error(error)
3737 SUPPORT_MSG = 'For documentation on this error, please visit:'
3838 ERROR_URL = 'https://www.selenium.dev/documentation/webdriver/troubleshooting/errors'
3939
40- class WebDriverError < StandardError ; end
40+ URLS = {
41+ NoSuchElementError : "#{ ERROR_URL } #no-such-element-exception" ,
42+ StaleElementReferenceError : "#{ ERROR_URL } #stale-element-reference-exception" ,
43+ InvalidSelectorError : "#{ ERROR_URL } #invalid-selector-exception" ,
44+ NoSuchDriverError : "#{ ERROR_URL } /driver_location"
45+ } . freeze
46+
47+ class WebDriverError < StandardError
48+ def initialize ( msg = '' )
49+ # Remove this conditional when all the error pages have been documented
50+ super ( URLS [ class_name ] ? "#{ msg } ; #{ SUPPORT_MSG } #{ URLS [ class_name ] } " : msg )
51+ end
52+
53+ def class_name
54+ self . class . name &.split ( '::' ) &.last &.to_sym
55+ end
56+ end
4157
4258 #
4359 # An element could not be located on the page using the given search parameters.
4460 #
4561
46- class NoSuchElementError < WebDriverError
47- def initialize ( msg = '' )
48- super ( "#{ msg } ; #{ SUPPORT_MSG } #{ ERROR_URL } #no-such-element-exception" )
49- end
50- end
62+ class NoSuchElementError < WebDriverError ; end
5163
5264 #
5365 # A command to switch to a frame could not be satisfied because the frame could not be found.
@@ -67,7 +79,7 @@ class UnknownCommandError < WebDriverError; end
6779
6880 class StaleElementReferenceError < WebDriverError
6981 def initialize ( msg = '' )
70- super ( "#{ msg } ; #{ SUPPORT_MSG } #{ ERROR_URL } #stale-element-reference-exception " )
82+ super ( "#{ msg } ; #{ SUPPORT_MSG } #{ URLS [ :StaleElementReferenceError ] } " )
7183 end
7284 end
7385
@@ -143,11 +155,7 @@ class ScriptTimeoutError < WebDriverError; end
143155 # Argument was an invalid selector.
144156 #
145157
146- class InvalidSelectorError < WebDriverError
147- def initialize ( msg = '' )
148- super ( "#{ msg } ; #{ SUPPORT_MSG } #{ ERROR_URL } #invalid-selector-exception" )
149- end
150- end
158+ class InvalidSelectorError < WebDriverError ; end
151159
152160 #
153161 # A new session could not be created.
@@ -232,11 +240,7 @@ class UnsupportedOperationError < WebDriverError; end
232240 # Indicates that driver was not specified and could not be located.
233241 #
234242
235- class NoSuchDriverError < WebDriverError
236- def initialize ( msg = '' )
237- super ( "#{ msg } ; #{ SUPPORT_MSG } #{ ERROR_URL } /driver_location" )
238- end
239- end
243+ class NoSuchDriverError < WebDriverError ; end
240244 end # Error
241245 end # WebDriver
242246end # Selenium
0 commit comments