-1

I tried selenium automation with webdriver but I keep getting errors. Please help me fix the problem

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep

browser = webdriver.Chrome("chromedriver.exe")
browser.get("https://python.org")

the Error I received:

File "C:\Users\LUCKY-PC\OneDrive\Desktop\Python\automation\selenium_test.py", line 2, in <module>
    from webdriver_manager.chrome import ChromeDriverManager

  File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\webdriver_manager\chrome.py", line 4, in <module>
    from webdriver_manager import utils

  File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\webdriver_manager\utils.py", line 8, in <module>
    import requests

  File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\requests\__init__.py", line 95, in <module>
    from urllib3.contrib import pyopenssl

  File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 109, in <module>
    orig_util_SSLContext = util.ssl_.SSLContext

AttributeError: module 'urllib3.util' has no attribute 'ssl_'

2 Answers2

0

Try with ChromeDriverManager().install():

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://python.org")
Max Daroshchanka
  • 2,698
  • 2
  • 10
  • 14
-1

It's better if you download the chrome driver and then provide the chrome driver path to code.

Go to your chrome browser and type chrome://settings/help. From here you can find your chrome version.

Then go to https://chromedriver.chromium.org/downloads to download a chrome driver that matches your chrome version.

Now give the path to of that driver in the code below.

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

class Driver_Class(webdriver.Chrome):
    def __init__(self, driver_path, teardown=False):
        self.driver_path = driver_path
        self.options = Options()
        self.options.headless = False
        self.driver = webdriver.Chrome(executable_path=self.driver_path,options=self.options)

        self.options.add_argument('--ignore-certificate-errors')
        self.options.add_argument('--ignore-ssl-errors')

        self.teardown = teardown
        os.environ['PATH'] += self.driver_path

        self.driver.implicitly_wait(30)
        self.driver.maximize_window()

    def get_driver(self):
        return self.driver

driverObj = Driver_Class("chrome_driver_path")
driver = driverObj.get_driver()

Now you can use this driver for the rest of your program.