impossible d'importer le VSCode «sélénium» [dupliquer]

Sep 13 2020

J'essaie d'utiliser le pilote Web pour automatiser le remplissage d'un formulaire, mais vscode ne peut pas importer du sélénium pour une raison quelconque. Des bibliothèques Python ont été ajoutées à mon chemin système

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()

Si ce n'est pas déjà évident, je suis un noob complet pour python

la sortie reçue lors de l'exécution à l'aide de coderunner dans VS est

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

Désolé si c'est super basique, j'essaie de le comprendre depuis plus de 5 heures maintenant et cela me rend fou :)

Merci pour toute aide

Réponses

HamzaRana Sep 14 2020 at 03:34

Cela fonctionne toujours pour moi.

Au lieu de:

driver = webdriver.Chrome()

Essayez d'ajouter l'emplacement au chromedriver.exe entre parenthèses:

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