Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DeprecationWarning with selenium/geckodriver

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading