T
T
Tula Electronic Samovar2021-11-28 13:44:03
Python
Tula Electronic Samovar, 2021-11-28 13:44:03

Selenium does not work in Python. Strange error when connecting the driver, what is it?

I am in substitution. I do everything as indicated in the example

# импорт библиотек
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By

chromedriver = r'c:\port\selenium\chrome\chromedriver.exe'
options = webdriver.ChromeOptions()
# options.add_argument('headless')  # для открытия headless-браузера
options = webdriver.ChromeOptions()
options.add_argument('headless')  # для открытия headless-браузера
#browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
browser = webdriver.Chrome(executable_path=chromedriver)

# browser = webdriver.Chrome(chromedriver)
# Переход на страницу входа
browser.get('https://www.pochta.ru/tracking#30000052425166')
# Поиск тегов по имени
browser.implicitly_wait(10)
WebElement = browser.find_element(By.CLASS_NAME, "TrackingCardMainInfo__Layout-sc-z7o53r-0 bHlmZW")


However, it gives a bunch of some incomprehensible errors, moreover, in modules that are loaded

D:\_proekt\pythonProject\chromepost\venv\Scripts\python.exe D:/_proekt/pythonProject/chromepost/main.py
D:\_proekt\pythonProject\chromepost\main.py:12: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser = webdriver.Chrome(executable_path=chromedriver)
Traceback (most recent call last):
  File "D:\_proekt\pythonProject\chromepost\main.py", line 12, in <module>
    browser = webdriver.Chrome(executable_path=chromedriver)
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "D:\_proekt\pythonProject\chromepost\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Stacktrace:
Backtrace:
  Ordinal0 [0x009E6903+2517251]
  Ordinal0 [0x0097F8E1+2095329]
  Ordinal0 [0x00882848+1058888]
  Ordinal0 [0x0089BC39+1162297]
  Ordinal0 [0x0089A2CF+1155791]
  Ordinal0 [0x008CAAAF+1354415]
  Ordinal0 [0x008CA71A+1353498]
  Ordinal0 [0x008C639B+1336219]
  Ordinal0 [0x008A27A7+1189799]
  Ordinal0 [0x008A3609+1193481]
  GetHandleVerifier [0x00B75904+1577972]
  GetHandleVerifier [0x00C20B97+2279047]
  GetHandleVerifier [0x00A76D09+534521]
  GetHandleVerifier [0x00A75DB9+530601]
  Ordinal0 [0x00984FF9+2117625]
  Ordinal0 [0x009898A8+2136232]
  Ordinal0 [0x009899E2+2136546]
  Ordinal0 [0x00993541+2176321]
  BaseThreadInitThunk [0x756A6359+25]
  RtlGetAppContainerNamedObjectPath [0x775E7B74+228]
  RtlGetAppContainerNamedObjectPath [0x775E7B44+180]


I'm confused... The driver file is located, the path is registered... What's the matter?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ab1, 2021-12-21
@vcomp71

This message is about selenum upgrade from v 3 to 4
if the task is temporary (before v5) - you can ignore)
The answer is just google the message
or
write the path to the chromedriver in the Env variable Path, then you don’t have to specify it when creating the object

A
alexbprofit, 2021-11-28
@alexbprofit

chrome installed?

T
Tula Electronic Samovar, 2021-12-04
@vcomp71

After the ordeal wrote the code

# импорт библиотек
from selenium import webdriver

chromedriver = r'c:\port\selenium\chrome\chromedriver.exe'
chrome_ = r'c:\Program Files (x86)\Google\Chrome\Application\chrome.exe'

options = webdriver.ChromeOptions()
options.binary_location = chrome_
chrome_driver_binary = chromedriver
driver = webdriver.Chrome(chrome_driver_binary)
# Переход на страницу входа
driver.get('https://www.pochta.ru/tracking#30000052425166')

The browser launches, goes to the page, but gives a strange error
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(chrome_driver_binary)

What means "the way is outdated"??? What needs to be updated?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question