def __get_driver_path(self, browser): default = os.path.split(os.path.realpath(__file__))[0] default = default + os.sep + '..' + os.sep + "resource" + os.sep + "driver" _browser = browser.lower() if _browser == "chrome": default = default + os.sep + _browser + os.sep + self.chrome_driver_version if System.get_os_name() == "linux": if System.is64bit(): default = default + os.sep + "linux64" else: default = default + os.sep + "linux32" default = default + os.sep + "chromedriver" elif System.get_os_name() == "windows": default = default + os.sep + "win32" + os.sep + "chromedriver.exe" elif System.get_os_name() == "macos": default = default + os.sep + "mac64" + os.sep + "chromedriver" elif _browser == "edge": default = default + os.sep + _browser + os.sep + self.edge_driver_version \ + os.sep + "MicrosoftWebDriver.exe" elif _browser == "firefox": default = default + os.sep + _browser + os.sep + self.firefox_driver_version if System.get_os_name() == "linux": if System.is64bit(): default = default + os.sep + "linux64" else: default = default + os.sep + "linux32" default = default + os.sep + "geckodriver" elif System.get_os_name() == "windows": if System.is64bit(): default = default + os.sep + "win64" else: default = default + os.sep + "win32" default = default + os.sep + "geckodriver.exe" elif _browser == "ie": default = default + os.sep + _browser + os.sep + self.ie_driver_version # Use win32 for IE driver only because of performance issue. # if (self.__is64bit()): # default = default + os.path.sep + "win64" # else: # default = default + os.path.sep + "win32" # default = default + os.path.sep + "IEDriverServer.exe" default = default + os.sep + "win32" + os.sep + "IEDriverServer.exe" return default
def _make_ff(self, proxy=None): cur_path = os.path.dirname(os.path.realpath(__file__)) cur_path = cur_path + os.sep + ".." + os.sep + 'log' + os.sep + 'geckodriver.log' fp = None if System.get_os_name().lower() == 'windows': target = os.path.expanduser('~') \ + os.sep + 'AppData' + os.sep + 'Roaming' + os.sep + 'Mozilla' + os.sep + 'Firefox' \ + os.sep + 'Profiles' fp = System.search_file_contains(target, '.default') firefox_profile = webdriver.FirefoxProfile(fp) if proxy is not None: host, port = proxy.split(r'//')[1].split(':')[0], proxy.split( r'//')[1].split(':')[1] firefox_profile.set_preference("network.proxy.http", host) firefox_profile.set_preference("network.proxy.http_port", int(port)) firefox_profile.set_preference("network.proxy.ssl", host) firefox_profile.set_preference("network.proxy.ssl_port", int(port)) firefox_profile.set_preference("network.proxy.socks", host) firefox_profile.set_preference("network.proxy.socks_port", int(port)) firefox_profile.set_preference("network.proxy.ftp", host) firefox_profile.set_preference("network.proxy.ftp_port", int(port)) firefox_profile.set_preference("network.proxy.no_proxies_on", 'localhost') firefox_profile.set_preference("network.proxy.type", 1) else: firefox_profile.set_preference("network.proxy.type", 0) firefox_capabilities = DesiredCapabilities.FIREFOX firefox_capabilities['acceptInsecureCerts'] = True firefox_capabilities['marionette'] = True binary = FirefoxBinary() return webdriver.Firefox( executable_path=self.__get_driver_path("firefox"), capabilities=firefox_capabilities, firefox_binary=binary, firefox_profile=firefox_profile, log_path=cur_path)