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()
我不明白有什么问题。如果有人理解这个问题,请解决这个问题。
任何帮助将不胜感激
发生这种情况是因为代码运行完毕后 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
,否则文件系统中的临时文件夹会被淹没
options.add_experimental_option("detach", True)
# notice, this will disable log out put,
# the browser close may due to no place to send logs
options.add_experimental_option('excludeSwitches', ['enable-logging'])