要求:
- 需要退出当前所有的谷歌浏览器(特别注意) 找到chrome的启动路径
- 启动命令windows:chrome --remote-debugging-port=9222
- 启动命令mac:Google Chrome --remote-debugging-port=9222
- 配置环境变量
-
mac 启动路径
- /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=9222
from time import sleep from selenium import webdriver from selenium.webdriver.chrome.options import Options class TestTestdemo(): def setup_method(self): options = Options() options.debugger_address = "127.0.0.1:9222" self.driver = webdriver.Chrome(options=options) self.driver.implicitly_wait(5) def teardown_method(self, method): self.driver.quit() def test_testdemo(self): self.driver.get("http://www.baidu.com") sleep(3)
end