def setUp(self): ''' set up test ''' os.environ["DISPLAY"] = ":99" ffx_bin = FirefoxBinary("/usr/bin/firefox") ffx_profile = FirefoxProfile() ffx_profile.accept_untrusted_certs = True self.driver = webdriver.Firefox(firefox_binary=ffx_bin, firefox_profile=ffx_profile)
def get_firefox_web_driver(): options = FOptions() options.set_capability('goog:loggingPrefs', {'performance': 'ALL'}) options.add_argument("--disable-infobars") options.add_argument("--disable-notifications") profile = FirefoxProfile() profile.accept_untrusted_certs = True LOGGER.setLevel(ERROR) driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options, firefox_profile=profile) return driver
def setUp(self): profile = FirefoxProfile() # Ignore certification profile.set_preference("webdriver_assume_untrusted_issuer", False) profile.set_preference("webdriver_accept_untrusted_certs", True) profile.accept_untrusted_certs = True # Set user agent profile.set_preference("general.useragent.override", "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4") profile.update_preferences() self.driver = webdriver.Firefox(profile) self.base_url = "http://m.finance.yahoo.co.jp/" self.driver.implicitly_wait(30) self.accept_next_alert = True
def setUp(self): profile = FirefoxProfile() # Ignore certification profile.set_preference("webdriver_assume_untrusted_issuer", False) profile.set_preference("webdriver_accept_untrusted_certs", True) profile.accept_untrusted_certs = True # Set user agent profile.set_preference( "general.useragent.override", "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4" ) profile.update_preferences() self.driver = webdriver.Firefox(profile) self.base_url = "http://m.finance.yahoo.co.jp/" self.driver.implicitly_wait(30) self.accept_next_alert = True
def function_driver(request): """ driver注入 @param request: @return: """ browser = request.config.getoption("--browser") # 用于本地启动是否开启浏览器设置,根据命令行传参,browser_opt判断,默认open browser_opt = request.config.getoption("--browser_opt") print("获取命令行传参:{}".format(request.config.getoption("--browser"))) type_driver = request.config.getoption("--type_driver") # 判断是本地还是远程 if type_driver == "local": if browser_opt == "open": if browser == "chrome": # 跳过非安全的https安全校验 chrome_options = CO() chrome_options.add_argument("--ignore-certificate-errors") driver = webdriver.Chrome(chrome_options=chrome_options) elif browser == "firefox": # 跳过非安全的https安全校验 profile = FP() profile.accept_untrusted_certs = True driver = webdriver.Firefox(firefox_profile=profile) elif browser == "ie": # 跳过非安全的https安全校验 capabilities = webdriver.DesiredCapabilities() capabilities['acceptSslCerts'] = True driver = webdriver.Ie(capabilities=capabilities) else: logging.info("发送错误浏览器参数:{}".format(browser)) else: if browser == "chrome": # 不开启浏览器窗口,后台运行测试代码 chrome_options = CO() chrome_options.add_argument('--headless') # 跳过非安全的https安全校验 chrome_options.add_argument('--ignore-certificate-errors') driver = webdriver.Chrome(chrome_options=chrome_options) elif browser == "firefox": # 不开启浏览器窗口,后台运行测试代码 firefox_options = FO() firefox_options.add_argument('--headless') # 跳过非安全的https安全校验 profile = FP() profile.accept_untrusted_certs = True driver = webdriver.Firefox(firefox_options=firefox_options, firefox_profile=profile) elif browser == "ie": # 不开启浏览器窗口,后台运行测试代码 ie_options = IEO() ie_options.add_argument('--headless') # 跳过非安全的https安全校验 capabilities = webdriver.DesiredCapabilities() capabilities['acceptSslCerts'] = True driver = webdriver.Ie(ie_options=ie_options, capabilities=capabilities) else: logging.info("发送错误浏览器参数:{}".format(browser)) yield driver # driver.close() driver.quit() elif type_driver == "remote": driver = Remote(command_executor=selenium_config["selenium_config"]["selenium_hub_url"], desired_capabilities={'platform': 'ANY', 'browserName': browser, 'version': '', 'javascriptEnabled': True}) yield driver # driver.close() driver.quit() else: logging.error("driver参数传递错误,请检查参数:{}".format(type_driver))
with open('list_result.csv', 'a', newline='') as csvfile: writer = csv.writer(csvfile) for row in data: writer.writerow(row) if __name__ == "__main__": sys.setrecursionlimit( 1000000 ) #设置最大递归次数(若不设置,默认值为998,递归998次后将出现"maximum recursion depth exceeded"的报错) firefoxProfile = FirefoxProfile() #firefoxProfile.set_preference('permissions.default.stylesheet', 2) #禁加载CSS #firefoxProfile.set_preference('permissions.default.image', 2) #禁加载图片 firefoxProfile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so', 'false') #禁加载Flash firefoxProfile.accept_untrusted_certs = True options = Options() #options.add_argument('-headless') #无浏览器参数 d = webdriver.Firefox(firefoxProfile, options=options) d.set_window_size(1600, 900) print("initiating...") data = [[ '序号', '申请编号', '学号', '护照姓名', '中文姓名', '护照号', '国籍', '专业', '学院', '经费来源', '学生类别', '学习期限', '修改日期', '修改时间', '状态', '操作' ]] login() print('checking...\n') loop() writecsv() print("the end") time.sleep(30)
Assunt = "DIREITO PENAL - Crimes contra a vida - Homicídio Simples" # PROCEDIMENTO: (Procedimentos possíveis: Inquérito Civil - IC, # Inquérito Policial - IP, # Procedimento Investigatório Criminal - PIC, # Procedimento Preparatório Inquérito Civil - PPIC ) Proced = "Inquérito Policial - IP" # UNIDADE: Unid = "PROMOTORIA DE JUSTIÇA DO III TRIBUNAL DO JÚRI" # INÍCIO DO CÓDIGO, NÃO ALTERE AS LINHAS ABAIXO profile = FirefoxProfile() profile.set_preference("browser.helperApps.neverAsk.saveToDisk", 'application/octet-stream') profile.accept_untrusted_certs = True driver = webdriver.Firefox(firefox_profile=profile) driver.get( 'https://sismpconsultapublica.mpsp.mp.br/ConsultarProcedimentos/ObterProcedimentos' ) driver.implicitly_wait(3) driver.find_element_by_xpath( "//select[@id='TipoProcedimento']/option[text()='" + Proced + "']").click() driver.find_element_by_xpath("//select[@id='UA']/option[text()='" + Unid + "']").click() btnbusca = driver.find_element_by_id('btnConsultar') assunto = driver.find_element_by_id('AssuntoTabUni')
def ost_driver(request): """ driver注入 @param request: @return: """ browser = request.config.getoption("--browser") # It is used to set whether or not to open the browser for local startup,browser_opt judge,default:open browser_opt = request.config.getoption("--browser_opt") logging.info(f'Get command line parameters:{request.config.getoption("--browser")}') type_driver = request.config.getoption("--type_driver") # Determine whether it is distributed locally or remotely if type_driver == "local": if browser_opt == "open": if browser == "chrome": # Skip non secure HTTPS security verification chrome_options = CO() chrome_options.add_argument("--ignore-certificate-errors") driver = webdriver.Chrome(chrome_options=chrome_options) elif browser == "firefox": # Skip non secure HTTPS security verification profile = FP() profile.accept_untrusted_certs = True driver = webdriver.Firefox(firefox_profile=profile) elif browser == "ie": # Skip non secure HTTPS security verification driver = webdriver.Ie() else: logging.info(f"Bad browser parameters:{browser}") else: if browser == "chrome": # Do not open the browser window, run the test code in the background chrome_options = CO() chrome_options.add_argument('--headless') # Skip non secure HTTPS security verification chrome_options.add_argument('--ignore-certificate-errors') driver = webdriver.Chrome(chrome_options=chrome_options) elif browser == "firefox": # Do not open the browser window, run the test code in the background firefox_options = FO() firefox_options.add_argument('--headless') # Skip non secure HTTPS security verification profile = FP() profile.accept_untrusted_certs = True driver = webdriver.Firefox(firefox_options=firefox_options, firefox_profile=profile) elif browser == "ie": # Do not open the browser window, run the test code in the background ie_options = IEO() ie_options.add_argument('--headless') # Skip non secure HTTPS security verification driver = webdriver.Ie(ie_options=ie_options) else: logging.info(f"Received incorrect browser parameters:{browser}") return driver elif type_driver == "remote": # Read selenium distributed configuration file selenium_config_path = os.path.join(os.getcwd(), "Conf", "config.yaml") selenium_config = FileOption.read_yaml(selenium_config_path) driver = Remote(command_executor=selenium_config["selenium_config"]["selenium_hub_url"], desired_capabilities={'platform': 'ANY', 'browserName': browser, 'version': '', 'javascriptEnabled': True}) return driver else: logging.error(f"driver parameter transfer error, please check the parameter:{type_driver}")