我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。
1分钟后我看到如下错误:
Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)
我的配置:
Chrome浏览器:66
ChromeBrowser: 2.39.56
又及,在Firefox中一切都很好
我遇到了同样的问题,我使用UBUNTU, PYTHON和OPERA浏览器。在我的例子中,这个问题是因为我有一个过时的operadriver版本。
解决方案:
1. 确保您安装了最新的opera浏览器版本(不要使用opera beta或opera developer),为此请到opera官方网站并从那里下载最新的opera_stable版本。
安装最新的opera驱动程序(如果你已经安装了一个opera驱动程序,你必须先使用sudo rm删除它…)
wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip
unzip operadriver_linux64.zip
sudo mv operadriver /usr/bin/operadriver
sudo chown root:root /usr/bin/operadriver
sudo chmod +x /usr/bin/operadriver
在我的情况下,最新的是80.0.3987,你可以看到
此外,我还安装了chromedriver(但因为我在测试之前做了,我不知道这是需要的),为了安装chromedriver,遵循上一步的步骤
好好享受吧,谢谢我!
示例硒代码
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
在我的情况下,这是ubuntu服务器上的CI代理帐户的问题,我用自定义——user-data-dir解决了这个问题
chrome_options.add_argument(“——user-data-dir = ~ / config / google chrome”)
CI代理使用的我的帐户没有必要的权限,有趣的是一切都在根帐户上工作
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')
driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url)
get_url = driver.current_url
print(get_url)
我遇到了同样的问题,在我的情况下,Linux系统中有两个不同的常见用户userera和userB。
userA第一次运行selinium程序成功启动chrome浏览器,当到达userB时,出现DevToolsActivePort文件不存在的错误。
我尝试了——remote-debug -port=9222选项,但它导致了一个新的异常:
selenium.common.exceptions.WebDriverException: Message: chrome不可达
I run google-chome目录,看到以下错误:
mkdir /tmp/Crashpad/new: Permission denied (13)
我搜索了这个问题,得到了这个:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/
chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")
感谢@johncylee。