Python Forum

Full Version: webdriver does not work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I just started a new project and chromedriver does not work, I have the newest version of pycharm, Google chrome, and chromedriver.

The first problem was:

from selenium import webdriver
dirver = webdriver.Chrome("C:/chromedriver.exe")
I got this:
{error1}

Then I found this site:

https://exerror.com/deprecationwarning-e...he_Service

So I changed my code to:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/chromedriver.exe')
driver = webdriver.Chrome(service=s)
Errors:
{error2}

I have no idea what ca be wrong.
Use Code Tags
You most download version 96,97 is still in beta.
chromedriver.exe most be in Environment Variables Path if unsure place it in C:\Windows\chromedriver.exe
Here a example setup.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time

#--| Setup
options = Options()
#options.add_argument("--headless")
#options.add_argument("--window-size=1980,1020")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
#--| Parse or automation
url = "https://www.youtube.com/results?search_query=python"
browser.get(url)
# Example of using both to parse
time.sleep(2)
soup = BeautifulSoup(browser.page_source, 'lxml')
use_bs4 = title = soup.find('a', id="video-title")
print(use_bs4.text.strip())
print('-' * 25)
use_sel = browser.find_elements_by_css_selector('#video-title > yt-formatted-string')
print(use_sel[0].text) 
Output:
Learn Python - Full Course for Beginners [Tutorial] ------------------------- Learn Python - Full Course for Beginners [Tutorial]
Thanks, now I used version 95 and it's working :)) and also sry for code tags and the rest of mistakes