Home > Back-end >  DeprecationWarning with selenium/geckodriver
DeprecationWarning with selenium/geckodriver

Time:05-18

What does the DeprecationWarning mean?

Also it seems like if i delete the "elem" functions it kind of works but when the chrome tab opens with the link it immediatelly closes again

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pyautogui

import unittest
import time


class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Chrome(
            executable_path=r'C:\Users\iwanh\Desktop\Geckodriver\geckodriver.exe')

    def test_search_in_python_org_true(self):
        driver = self.driver
        driver.get("https://e-learning.nyc.gr/login/index.php")

        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.clear()
        elem.send_keys("pycon")
        time.sleep(3)
        elem.send_keys(Keys.RETURN)
        self.assertNotIn("No results found.", driver.page_source)

    def test_search_in_python_org_false(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.clear()
        elem.send_keys("ljueragiuhoerg")
        elem.send_keys(Keys.RETURN)
        time.sleep(2)
        self.assertIn("No results found.", driver.page_source)

    def tearDown(self):
        self.driver.close()


if __name__ == "__main__":
    unittest.main()

Outputs of code Output 1 Output 2

CodePudding user response:

With selenium4 as the key executable_path is deprecated you have to use an instance of the Service() class along with ChromeDriverManager().install() command as below.

Pre-requisites

  • Ensure that: Selenium is upgraded to v4.0.0

Solutions:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
  • Related