How to stop getting following error? while opening chrome browser from python

satyam rastogi :

Note: Code opens the chrome browser but gives the above error too.

    from selenium import webdriver
    main_url = 'https://www.linkedin.com' # URL A
    tab_url = 'https://www.google.com' # URL B
    chromedriver = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'

    # Open main window with URL A
    browser= webdriver.Chrome(chromedriver)
    browser.get(main_url)

Getting the below error when try to run the script.

 Error:  Message: Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
supputuri :

I would prefer using the webdriver_manager which will take care setting the execution_path variables and also download the driver automatically when you run the script.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

main_url = 'https://www.linkedin.com' # URL A
tab_url = 'https://www.google.com' # URL B

# Open main window with URL A
browser= webdriver.Chrome(ChromeDriverManager().install())
browser.get(main_url)

If you are planning to open both urls in 2 separate tabs, use the below.

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

main_url = 'https://www.linkedin.com' # URL A
tab_url = 'https://www.google.com' # URL B

# Open main window with URL A
browser= webdriver.Chrome(ChromeDriverManager().install())
browser.get(main_url)

#print the current url
print(driver.current_url)
# open tab_url in new window
driver.execute_script("window.open(tab_url)")
# switch to the new window
driver.switch_to.window(driver.window_handles[1])
# check if the url is equals to tab_url
print(driver.current_url)
if driver.current_url == tab_url:
    print(driver.current_url + " - Passed.")
    driver.close()
# close the window
driver.close()

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=383529&siteId=1