我想重写方法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)