selenium模拟登录使用https协议的网址时报错的解决方法

公司的测试地址是https协议的,使用使用默认的selenium登录时会出现安全提示的报错,导致无法模拟自动化。

对此,笔者通过网上查找资料和实践,发现只需要简单的修改一下浏览器驱动的配置即可解决。

具体代码如下:

#修改浏览器驱动的配置(忽略证书错误)
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
driver = webdriver.Chrome(options=options)
#下面的步骤与普通的操作一致
driver.get("https://xxxxxxxx")
driver.find_element(By.XPATH,'//*[@id="j_username"]').send_keys("xxxxxx")
driver.find_element(By.XPATH,'//*[@id="j_password"]').send_keys("xxxxxx")
driver.find_element(By.XPATH,'//*[@id="authen1Form"]/button').click()

posted @ 2022-10-28 16:02  种下一颗树  阅读(391)  评论(0)    收藏  举报