首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法导入“selenium”VSCode

无法导入“selenium”VSCode
EN

Stack Overflow用户
提问于 2020-09-14 03:19:22
回答 1查看 1.4K关注 0票数 4

我试图使用web驱动程序自动填写表单,但是vscode由于某些原因无法导入selenium。Python库已添加到我的系统路径中。

代码语言:javascript
运行
复制
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执行时收到的输出为

代码语言:javascript
运行
复制
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+时间,这让我发疯了:)

谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2020-09-14 03:34:53

这对我来说总是管用的。

而不是:

代码语言:javascript
运行
复制
driver = webdriver.Chrome()

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

代码语言:javascript
运行
复制
driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32_2 v84\chromedriver.exe')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63877645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档