selenium的debug模式打开网址总显示“隐私设置错误”

整了好久也没弄好, 之前把 self.driver = webdriver.Chrome(options=chrome_options)
改成了(chrome_options=chrome_options)好了一次, 今天跑又不可以了,google 浏览器是否需要配置什么? 测试过程中safari是打开的。

条件:

  1. Mac 电脑
  2. 在监控器将chrome相关的进程全部杀掉了
  3. 开器端口命令:sudo /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --test-type --ignore-certificate-error --remote-debugging-port=9222
    // 去掉sudo也一样

现象:
执行命令终端提示报错:
2020-07-19 19:16:07.231 Google Chrome[8914:402846] KSPaths accessing user domain product actives store as root. [com.google.Keystone.SharedErrorDomain:1001 - ‘KSPaths.m:402’]

DevTools listening on ws://127.0.0.1:9222/devtools/browser/e1e79d43-a9f9-4062-84d1-f80ba1a7d76a
2020-07-19 19:16:07.232 Google Chrome[8914:402846] Error while attempting to write actives: (<KSError:0x7f954087acc0
domain=“com.google.Keystone.SharedErrorDomain”
code=1001
userInfo={
NSLocalizedDescription = “KSPaths accessing user domain product actives store as root.”;
line = 402;
filename = “KSPaths.m”;
function = “+[KSPaths userKeystoneSubDirectoryWithName:error:]”;
date = 2020-07-19 11:16:07 +0000;
}

)
[8914:775:0719/191607.235417:ERROR:dock.mm(156)] dock_plist is not an NSDictionary
2020-07-19 19:16:07.785 Google Chrome[8914:402846] KSPaths accessing user domain Keystone directory as root. [com.google.Keystone.SharedErrorDomain:1001 - ‘KSPaths.m:331’]
2020-07-19 19:16:07.785 Google Chrome[8914:402846] KSBundle could not obtain user bundle path. [com.google.Keystone.SharedErrorDomain:1201 - ‘KSBundle.m:44’] (KSPaths accessing user domain Keystone directory as root. [com.google.Keystone.SharedErrorDomain:1001])
2020-07-19 19:16:07.787 Google Chrome[8914:402846] KSPaths accessing user domain Keystone directory as root. [com.google.Keystone.SharedErrorDomain:1001 - ‘KSPaths.m:331’]
2020-07-19 19:16:07.787 Google Chrome[8914:402846] KSBundle could not obtain user bundle path. [com.google.Keystone.SharedErrorDomain:1201 - ‘KSBundle.m:44’] (KSPaths accessing user domain Keystone directory as root. [com.google.Keystone.SharedErrorDomain:1001])
[8923:19971:0719/191607.809422:ERROR:ssl_client_socket_impl.cc(959)] handshake failed; returned -1, SSL error code 1, net_error -207

打开的网页titil提示“隐私设置错误”, 见附件

用的是老师的原代码

import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

class Test():
def setup_method(self, method):
chrome_options = Options()
#和浏览器打开的调试端口进行通信
#浏览器要使用 --remote-debugging-port=9222 开启调试
chrome_options.debugger_address = “127.0.0.1:9222”
self.driver = webdriver.Chrome(options=chrome_options)

def test_baidu(self):
    self.driver.get("https://www.baidu.com/")
    self.driver.find_element(By.ID, "kw").send_keys("霍格沃兹测试学院")
    self.driver.find_element(By.ID, "su").click()
    time.sleep(2)
    self.driver.find_element(By.LINK_TEXT, "霍格沃兹测试学院 – 测试开发工程师的黄埔军校").click()

使用网址改成https就好了

https 没有用

看下chrome drvier的路径,可以尝试放在项目下面。浏览器关闭自动更新

1、检查下chrome是否开启代理等工具。
2、尝试下手动打开 https://www.testing-studio.com/
3、使用webdriver直接打开浏览器,不进行复用,看下是否可以正常打开。

无代理, 手动可以打开https的这些网址
复用就不行,都尝试过了不行,百度可以,奇怪
self.driver.get(“https://www.testing-studio.com/”)
time.sleep(3)
self.driver.get(“https://www.sina.com.cn”)
time.sleep(3)
self.driver.get(“https://www.163.com”)
不复用就可以。

是复用的时候,可以打开百度吗

是复用模式下首次可以打开百度,但是再次是否可以打开未试过

1、修改脚本,在百度搜索其他内容,然后进行点击跳转,看下是否正常
2、修改脚本,在必应搜索,然后进行点击跳转,看下是否正常

在debug模式启动后,我将启动的浏览器清空了cookie 后。 baidu也打不开了。 在这个模式下的浏览器中手动输入url 都无法打开。

重启电脑,或者重新安装浏览器试试

先不说其他问题,就现在这个问题而言,加个参数应该可以--test-type --ignore-certificate-errors

啥意思? 去掉着这个参数吗? 我命令里面就加了这个参数

去掉也不可以

也不可以 浏览器我我看看换个旧版本的看看吧

换了淘宝的源下的驱动。mac居然不认淘宝下的。提示打不开,又换回原来的了。 太难了。

把chrome卸载了,重新安装也不行吗

  • 不用sudo 直接使用命令/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222开启一个调试模式的chrome
  • 打开127.0.0.1:9222页面确认chrome的远程调试模式正常开启
  • 执行脚本查看是否还会报私密连接问题
  • 如果又出现了私密连接问题,点击左上角的不安全 查看证书内容截图保存发出来看看image
  • 将地址栏中的访问地址完整复制出来看看是否访问的地址不是https开头的
  • 确认一下chrome浏览器的配置中是否有配置代理
  • 确认一下是否启动了charles等代理工具并开启了全局代理
  • 确认一下hosts中是否将域名解析到了特定的ip中
  • 可以去终端里面ping一下该域名看看IP地址是否正常

我的意思是加个参数,最后变成这样的命令,然后我加不加这个参数访问https://www.baidu.com都是没有提示证书问题的,看你试试看吧

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --test-type --ignore-certificate-errors

多谢解决了, 应该sudo的原因