Python Forum

Full Version: help with selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
why it doesnt work?

my code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.google.com")
error:
Error:
Traceback (most recent call last): File "C:/Users/MSI/PycharmProjects/fblogin/fb.py", line 2, in <module> driver = webdriver.Chrome() File "C:\Users\MSI\PycharmProjects\fblogin\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "C:\Users\MSI\PycharmProjects\fblogin\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "C:\Users\MSI\PycharmProjects\fblogin\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\MSI\PycharmProjects\fblogin\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\MSI\PycharmProjects\fblogin\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.18363 x86_64)
(Jan-01-2021, 03:41 PM)ZinkQ Wrote: [ -> ]Message: unknown error: cannot find Chrome binary
You most download Chrome webdriver.
So chromedriver.exe most be in Windows path or same folder as you run script from.
Working example,most also push the accept button before can search.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
import time

#--| Setup
options = Options()
#options.add_argument("--headless")
options.add_argument('--log-level=3')
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
browser.get("http://www.google.com")
time.sleep(2)
browser.switch_to.frame(0)
accept_button = browser.find_elements_by_css_selector('#introAgreeButton')[0]
accept_button.submit()
time.sleep(2)
search_bar = browser.find_elements_by_css_selector('div.a4bIc > input')[0]
search_bar.send_keys('2021')
search_bar.submit()
As far as the path to the driver, there are slight differences in get it to work on Windows and Linux.

Linux:
DRIVER_PATH = '/usr/bin/chromedriver'
driver = webdriver.Chrome(options = options, executable_path=DRIVER_PATH)

Windows:
DRIVER_PATH = 'C:\webscrape\chromedriver\chromedriver_86.exe'
driver = webdriver.Chrome(options = options, executable_path=DRIVER_PATH)

*Note that there are other differences in getting web scrape scripts to work on Windows and Linux. In other words a script that works fine on Windows likely will not work but just copying and pasting to Linux. Not just the pathing but other things are different. Also there are different versions of chromedriver.