我想覆盖该方法Selenium::WebDriver.for
.这是我试过的:
module SeleniumWebDriverExtension def self.for(browser, *args) if browser != :phantomjs super(browser, *args) else options = { "phantomjs.cli.args" => ["--ssl-protocol=tlsv1"] } capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs(options) super(browser, desired_capabilities: capabilities) end end end Selenium::WebDriver.prepend(SeleniumWebDriverExtension)
但是我在Selenium::Webdriver.for(:phantomjs)
调用时遇到错误.
NoMethodError: super: no superclass method `for' for Selenium::WebDriver::Driver:Class
如何从重写方法调用原始方法?
module SeleniumWebDriverExtension def for(browser, *args) ... end end Selenium::WebDriver.singleton_class.prepend(SeleniumWebDriverExtension)