-6

I'm trying to use selenium with Python to click a button on an HTML web page.Whenever I run the code, I get the following error:

'chromedriver' executable needs to be in PATH

I'm trying to click the "Play" button on this website: https://podcasts.apple.com/us/podcast/python-at-the-us-federal-election-commission/id979020229?i=1000522628049

Code:

driver = webdriver.Chrome(executable_path="C:/path/to/chromedriver")
time.sleep(3)
driver.get('https://podcasts.apple.com/us/podcast/python-at-the-us-federal-election-commission/id979020229?i=1000522628049')
button = driver.find_element(By.XPATH, '//*[@id="ember99"]/div/div/section/div[1]/div[1]/div/div/button')
button.click()
Chandella07
  • 2,089
  • 14
  • 22
Wilson T.
  • 11
  • 1
  • 4
  • 2
    Stupid question first: is chromedriver actually located in the path you are specifying? – C. Peck May 31 '21 at 18:16
  • 2
    `"C:/path/to/chromedriver"` Replace this with the actual path to the chromedriver. Which I assume you have downloaded. Something like `D:/chromedriver/chromedriver.exe` – Abhishek Rai May 31 '21 at 18:31

2 Answers2

0

From the error 'chromedriver' executable needs to be in PATH it seems like your chromedriver is not in the PATH environment variables. based on your OS check if chromedriver path exists in environment path variable.

Then try with below code: raw string with complete path of .exe of chromedriver.

from selenium import webdriver

driver = webdriver.Chrome(executable_path=r'C:\Users\Desktop\chromedriver_win64\chromedriver.exe') # complete path with .exe
driver.get('https://www.google.com')
Chandella07
  • 2,089
  • 14
  • 22
-1

Since you're using Windows, the path that you've written should look like:

'C:\\Studies\\PYTHON\\Web Scrapers'

Windows accepts "\\" when mentioning the path. Attached a screenshot for your reference!

Check this out

UPDATE: This is the code that I had written to scrape a website. You can check it here.

for link in links[:5]:
    # Extract the scores
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    path = "C:\\Users\\lenovo\\Documents\\chromedriver.exe"
    driver = webdriver.Chrome(path, options = options)
    driver.get(link)

You can check out the entire code HERE.