我在Windows 10上使用带有Python 3.7.3的Selenium。
如果我将代码包装在一个类中,则浏览器在打开页面后立即终止:
'''
Program to show how to open chrome browser using selenium webdriver
'''
from selenium import webdriver
#import os
class run_chrome_tests(object):
def test_method(self):
# This is the location of the chrome driver saved into a variable
#driver_location = "D:\\Udemy_Python\\Libs\\chromedriver.exe"
# Letting the system environment know the location of the chrome driver
#os.environ["webdriver.chrome.driver"] = driver_location
# Letting the chrome browser know the location of the chrome driver
driver = webdriver.Chrome()
driver.get("http://www.letskodeit.com")
ch = run_chrome_tests()
ch.test_method()
答案 0 :(得分:0)
检查Chrome浏览器的版本和chrome驱动程序的版本,如果驱动程序不兼容,则浏览器在打开后立即终止,请尝试同时使用最新版本