Python Forum

Full Version: Cannot open Chrome
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://www.google.com/")
When execute this script via CMD. It showed me this error message.

Capture
The simplest solution is to have chromedriver.exe is same folder as you run script.
When it complain a about PAth,it mean Environment Variables Path.
Example so i C:\cmder\bin\ added to Windows Path.
More in tutorial here Web-scraping part-2.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

#--| Setup uncomment for headless
chrome_options = Options()
#chrome_options.add_argument("--headless")
#chrome_options.add_argument('--disable-gpu')
#chrome_options.add_argument('--log-level=3')
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe')
#--| Parse or automation
browser.get('https://duckduckgo.com')
input_field = browser.find_elements_by_css_selector('#search_form_input_homepage')
input_field[0].send_keys('car' + Keys.RETURN)
time.sleep(3)
images_link = browser.find_elements_by_link_text('Bilder') # Or contry name of Images
images_link[0].click()
time.sleep(5)
browser.quit()
(Jan-25-2019, 05:30 PM)snippsat Wrote: [ -> ]The simplest solution is to have chromedriver.exe is same folder as you run script.
When it complain a about PAth,it mean Environment Variables Path.
Example so i C:\cmder\bin\ added to Windows Path.
More in tutorial here Web-scraping part-2.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

#--| Setup uncomment for headless
chrome_options = Options()
#chrome_options.add_argument("--headless")
#chrome_options.add_argument('--disable-gpu')
#chrome_options.add_argument('--log-level=3')
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe')
#--| Parse or automation
browser.get('https://duckduckgo.com')
input_field = browser.find_elements_by_css_selector('#search_form_input_homepage')
input_field[0].send_keys('car' + Keys.RETURN)
time.sleep(3)
images_link = browser.find_elements_by_link_text('Bilder') # Or contry name of Images
images_link[0].click()
time.sleep(5)
browser.quit()

Yes. When I install Python 3.7.2, I did click the PATH setting.
But somehow, I watch other people tutorials they just use .Chrome() instead?
(Jan-26-2019, 04:06 AM)gahhon Wrote: [ -> ]Yes. When I install Python 3.7.2, I did click the PATH setting.
That was not what meant,but you can put chromedriver.exe in python 3.7 folder as it's in Windows Path.
But you have chosen the annoying long default path and not eg C:\Python37.
Python 3.6/3.7 and pip installation under Windows.
(Jan-26-2019, 04:06 AM)gahhon Wrote: [ -> ]But somehow, I watch other people tutorials they just use .Chrome() instead?
Yes it did work like that before,but after update executable_path= is required or as mention chromedriver.exe is same folder as script.
So if you use python 3.7 folder eg browser = webdriver.Chrome(executable_path=r'path_of_37_folder.chromedriver.exe.')