Problem upgrading from Selenium 3 to Selenium 4
Asked Answered
S

1

0

I have a working Python script on Windows using Selenium 3.141.0. When I switch to Selenium 4.9.1, I get the following error:

selenium.common.exceptions.WebDriverException: Message: <!-- IE friendly error message walkround.        
E                if error message from server is less than   
E                512 bytes IE v5+ will use its own error     
E                message instead of the one returned by      
E                server.                                 -->

... bunch of html/css tags ...

E               <div class="logo"></div>
E               <h1>504 DNS look up failed</h1>
E               <p>The webserver reported that an error occurred while trying to access the website. Please return to the previous page.</p>
E               <table><tbody>
E                   <tr>
E                       <td>URL</td>
E                       <td>http://localhost:62789/session</td>
E                   </tr>
E               </tbody></table>

For troubleshooting, I tried the simplest possible code where I tried various combinations of options and no options:

def test_chrome_sel4():
    chrome_opts = webdriver.ChromeOptions()
    chrome_opts.add_argument('--no-sandbox')
    #chrome_opts.add_argument("--headless")
    chrome_opts.add_argument('--disable-dev-shm-usage')
        
    
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_opts)
    driver.get("https://www.google.com")
    sleep(4)
    driver.quit()

From the output, it shows the use of the driver, and if I delete the driver, the code downloads it, so that part is working.

From Selenium 3 to 4, I made changes to use the new Service mechanism for creating the driver. Is there something else that is not backward compatible to Selenium 3?

Solecism answered 1/6, 2023 at 20:51 Comment(0)
L
0

When you migrate from selenium v3.141.0 to v4.9.1, one library you can stop using is ChromeDriverManager. From selenium v4.6.0 and onwards, selenium's inbuilt tool known as Selenium Manager will handle the browser and browser drivers. In other words, latest selenium has an inbuilt feature to manage drivers, so you don't need an external library.

You can replace the below line:

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=chrome_opts)

To simply:

driver = webdriver.Chrome(options=chrome_opts)

Official reference: Introducing Selenium Manager

Lakia answered 2/6, 2023 at 8:56 Comment(1)
Hi @Shawn, thanks for the update on the newest way to create a driver. Unfortunately I get the same error using the new method.Solecism

© 2022 - 2024 — McMap. All rights reserved.