4

I am trying to use web driver to automate a form fill, however vscode is unable to import selenium for some reason. Python libraries have been added to my system path

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

If it's not already obvious, I am a complete noob to python

the output received upon execution using coderunner in VS is

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

Sorry if this is super basic, I have been trying to figure it out for 5+ hours now and it's driving me crazy :)

Thank you for any help

1 Answers1

0

This works for me always.

Instead of:

driver = webdriver.Chrome()

Try adding the location to the chromedriver.exe inside the parenthesis:

driver = webdriver.Chrome(executable_path=r'C:\chromedriver_win32_2 v84\chromedriver.exe')
Hamza Rana
  • 137
  • 9
  • Thank you! The script is working now however errors are still present in IDE :(. Page is opening, but none of the interactions are happening – Will Jackson Sep 14 '20 at 04:05