英文:
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()
英文:
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()
- selenium version = 4.9.1
- python version = 3.11.3
I don't understand what's the problem. If anyone understand the problem please fix this.
Any help would be much appreciated
答案1
得分: 0
这是因为 Chrome 在代码运行完成后会自动关闭。
你可能想要使用以下脚本进行测试:
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()
注意:最后仍需执行 driver.quit
,否则你的文件系统临时文件夹会被淹没。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论