【发布时间】:2020-12-31 18:46:37
【问题描述】:
我正在尝试使用 Web 驱动程序来自动填写表单,但是由于某种原因 vscode 无法导入 selenium。 Python 库已添加到我的系统路径中
import json
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Chrome()
driver.get("https://validwebsite/").driver.set_window_size(1054, 680)
driver.find_element(By.CSS_SELECTOR, ".nav > #loginLink").click()
driver.find_element(By.CSS_SELECTOR, ".btn-soundcloud").click()
driver.find_element(By.CSS_SELECTOR, ".form-element > span").click()
driver.find_element(By.CSS_SELECTOR, ".SideBarMenuLink").click()
driver.find_element(By.CSS_SELECTOR, "li:nth-child(1) > .sidebarLink > .sidebarlinktext").click()
driver.find_element(By.CSS_SELECTOR, ".list-group-item:nth-child(17) .TitleText-SP").click()
如果还不是很明显,我完全是 python 菜鸟
在 VS 中使用 coderunner 执行时收到的输出是
C:\Users\willj>python -u "d:\arcBooking.py"
Traceback (most recent call last):
File "C:\Users\willj\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\arcBooking.py", line 11, in <module>
driver = webdriver.Chrome()
File "C:\Users\willj\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\willj\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
对不起,如果这是超级基本的,我已经尝试了 5 个多小时了,这让我发疯了 :)
感谢您的帮助
【问题讨论】:
-
看起来你的 chromedriver 路径设置不正确,如果你使用的是 ubuntu 则将驱动文件放入 /usr/local/bin
-
把chromedriver放到c:\Windows
-
您可以使用 chrome 驱动程序管理器轻松设置这一切。
标签: python selenium visual-studio-code python-import