Chrome浏览器在从Selenium加载后退出

huangapple go评论135阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月17日 16:24:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76269990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定