selenium-webdriverselenium-chromedriverwebdriverselenium-ide

Chrome browser quit after loading from selenium


from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService`
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

driver.get('https://www.adamchoi.co.uk/overs/detailed')

all_matches_button = driver.find_element(By.XPATH, "//label[@analytics-event='All matches']")
all_matches_button.click()

# driver.quit()

I don't understand what's the problem. If anyone understand the problem please fix this.

Any help would be much appreciated


Solution

  • That occurs because chrome automatically closes when the code has finished running.

    You might wanna use the following script for testing:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService`
    from selenium.webdriver.common.by import By
    from webdriver_manager.chrome import ChromeDriverManager
    
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
    
    driver.get('https://www.adamchoi.co.uk/overs/detailed')
    
    all_matches_button = driver.find_element(By.XPATH, "//label[@analytics-event='All matches']")
    all_matches_button.click()
    
    input("Press ENTER to quit")
    driver.quit()
    

    Note: You'll still want to execute driver.quit in the end, as the temporary folder in your filesystem gets flooded elsewise