你好,我正试图在Python中运行以下代码。
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
def verify_title():
# Navigate to the website
driver.get("https://google.com")
# Get the title of the page
title = driver.title
# Verify the title
expected_title = "Google"
if title == expected_title:
print("Title verification successful!")
else:
print(f"Title verification failed. Expected '{expected_title}, but got '{title}'.")
# Close the browser
driver.quit()
if __name__ == '__main__':
verify_title()
字符串
它成功运行,输出“标题验证成功!”,但Chrome浏览器立即关闭。
我甚至删除了代码驱动程序。quit()来看看这是否有什么不同,但仍然是同样的问题。
谢谢
1条答案
按热度按时间vcirk6k61#
修改代码如下:
字符串
有关
detach
选项的更多详细信息,请参阅此答案:https://stackoverflow.com/a/77402087/7598774