imfat123
imfat123

Reputation: 81

Python, error with web driver (Selenium)

    import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)

I am getting the error:

FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

I am not sure whythis is happening, because I imported selenium already.

Upvotes: 8

Views: 24116

Answers (3)

Paul
Paul

Reputation: 1

If you are using a Mac, then don't include '.exe' I put the selenium package directly into my Pycharm project that I called 'SpeechRecognition'. Then in the selenium file, navigate to: /selenium/webdriver/chrome, then copy and paste the 'chromedriver.exe' file you downloaded most likely from [here][1] Try this script if you are using PyCharm IDE or similar. This should open a new Google window for you.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Chrome('/Users/Name/PycharmProjects/SpeechRecognition/selenium/webdriver/chrome/chromedriver')
browser.get('http://www.google.com')

Then if you want to automatically search an item on Google, add these lines below and run. You should see an automatic google search window opening up. It might disappear quickly but to stop that, you can simply add a while loop if you want or a timer

search = browser.find_element_by_name('q')
search.send_keys('How do I search an item on Google?')
search.send_keys(Keys.RETURN)


  [1]: https://sites.google.com/a/chromium.org/chromedriver/home

Upvotes: 0

user6731023
user6731023

Reputation:

Best way to eliminate this Exception without altering the code eevn single line is to add the chromedriver.exe( or nay other browser driver files) in to Python

  1. site_packages/scripts directory for windows
  2. dist_package/scripts for Linux

Please check this solution, it works.

Upvotes: 0

Vardhman Patil
Vardhman Patil

Reputation: 517

Either you provide the ChromeDriver path in webdriver.Chrome or provide the path variable

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driverLocation = 'D:\Drivers\chromedriver.exe' #if windows
driver = webdriver.Chrome(driverLocation) 
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)

Upvotes: 9

Related Questions