来自webdriver\u manager.chrome导入ChromeDriver manager的“未解决的引用错误”

2024-04-23 20:35:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个应用程序,将与网站进行交互,下面列出了重要的代码。因此,当从“webdriver\u manager.chrome”导入“ChromeDriverManager”时,我会得到错误“未解析引用'webdriver\u manager'”和“未解析引用'ChromeDriverManager'”。问题是,我想自动更新chromedriver,这是我提出的解决方案,但在pycharm中运行它时不起作用,但当我从控制台运行它时,它会起作用……有人对此有解决方案吗?因为我更喜欢在pycharm中测试代码,而不是每次从控制台启动代码

from selenium import webdriver 
from webdriver_manager.chrome import ChromeDriverManager # important for chromedriver-autoinstall
import time
p= ChromeDriverManager()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging", "enable-automation"])
# disables 'Browser is managed by test software' and surpresses error with USB device
driver = webdriver.Chrome(executable_path=p.install(), options=chrome_options)
# see above + install right version of chromedriver
t = 2  # time to wait for input of number
i = 1  # current round
duration = 1    

Tags: 代码fromimportaddfortimemanagerchrome