整了好久也没弄好, 之前把 self.driver = webdriver.Chrome(options=chrome_options)
改成了(chrome_options=chrome_options)好了一次, 今天跑又不可以了,google 浏览器是否需要配置什么? 测试过程中safari是打开的。
条件:
- Mac 电脑
- 在监控器将chrome相关的进程全部杀掉了
- 开器端口命令: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()