无法导入“硒” VSCode

时间:2020-09-14 03:19:22

标签: python selenium visual-studio-code python-import

我正在尝试使用Web驱动程序来自动执行表单填充,但是由于某些原因,vscode无法导入硒。 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中使用代码运行器执行时收到的输出是

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个多小时,这让我发疯了:)

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

这总是对我有用。

代替:

driver = webdriver.Chrome()

尝试将位置添加到括号内的 chromedriver.exe 中:

driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32_2 v84\chromedriver.exe')