我是编程的新手,Python大约2个月前开始使用Python文本,正在浏览Sweigart的自动化无聊的东西.我正在使用IDLE并且已经安装了selenium模块和Firefox浏览器.每当我尝试运行webdriver函数时,我都会得到:
from selenium import webdriver
browser = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
例外: -
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>
Traceback (most recent call last):
File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
self.stop()
File …Run Code Online (Sandbox Code Playgroud) 很长时间以来,我一直在使用python机器人来完成一些工作任务。除其他外,机器人必须通过身份验证窗口。
python程序中的代码如下:
driver = webdriver.Firefox(firefox_profile=profile)
...
driver.get('https://example.com')
driver.switch_to.alert.send_keys('123456' + Keys.TAB + '123456')
driver.switch_to.alert.accept()
Run Code Online (Sandbox Code Playgroud)
但是昨天它抛出了这个错误:
selenium.common.exceptions.WebDriverException:消息:不支持提示用户类型的用户提示
我一直在搜索,但是我什至没有找到有关这种异常以及如何处理此问题的结果。
有任何想法吗?
提前致谢!
首先,机器和包装规格:我正在运行:
ChromeDriver version 75.0.3770.140
Selenium: version '3.141.0'
WSL (linux subsystem) of windows 10
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过 Selenium 运行 chrome 浏览器。我发现:这些命令,通过谷歌浏览器使用硒。
我有一个测试目录,其中仅包含 chromedriver 二进制文件和脚本。目录位置为:/home/kela/test_dir/
我运行了代码:
import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
options = Options()
options.binary_location='/home/kela/test_dir/chromedriver'
driver = webdriver.Chrome(chrome_options = options,executable_path='/home/kela/test_dir/chromedriver')
Run Code Online (Sandbox Code Playgroud)
该代码的输出是:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么当同一个脚本适用于其他没有功能的脚本时我需要功能?我确实尝试添加:
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
Run Code Online (Sandbox Code Playgroud)
但我得到了同样的错误。所以我不确定我需要添加哪些功能(考虑到它对没有它的其他人也适用?)
编辑 1:解决 DebanjanB 的以下评论:
Chromedriver 位于预期位置。我使用的是 Windows 10。从这里开始,预期位置是 C:\Program …
selenium google-chrome webdriver selenium-chromedriver selenium-webdriver