Selenium Chrome Driver最新版本100.0.4896.60发布

需积分: 12 2 下载量 122 浏览量 更新于2024-11-04 收藏 6.1MB ZIP 举报
这是一个重要的资源,对于使用Selenium进行自动化测试的前端开发者和测试工程师来说,这是一个必不可少的工具。Selenium是一个强大的工具,它允许开发者编写测试脚本来模拟用户与浏览器的交互,从而对Web应用进行自动化测试。 Selenium Chrome Driver是Selenium家族中的一员,专门用于Chrome浏览器。它是Selenium与Chrome浏览器之间的桥梁,允许Selenium控制Chrome浏览器进行各种操作,如打开网页、点击按钮、填写表单等。 Selenium Chrome Driver 100.0.4896.60版本的发布,带来了许多新的特性和改进。例如,它可能包括对Chrome浏览器新版本的支持,提高了与Chrome浏览器的兼容性,增强了脚本的执行效率,或者增加了对新的Web标准的支持。这对于前端开发者和测试工程师来说,无疑是一个好消息。 Selenium Chrome Driver的安装和使用都非常简单。首先,你需要下载与你的Chrome浏览器版本相对应的Selenium Chrome Driver。然后,你需要在你的测试脚本中指定Selenium Chrome Driver的路径,这样Selenium才能找到并使用它。最后,你就可以在你的测试脚本中使用Selenium提供的各种方法来控制Chrome浏览器了。 总的来说,Selenium Chrome Driver 100.0.4896.60是一个非常重要的资源,对于使用Selenium进行自动化测试的前端开发者和测试工程师来说,它可以帮助他们更有效地进行Web应用的测试。"

from selenium import webdriver from selenium.webdriver.chrome.options import Options import time from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def init_driver(reuse_session=True): if reuse_session: # 连接已存在的调试会话 chrome_options.debugger_address = "127.0.0.1:9222" else: # 创建新会话时配置调试参数 chrome_options.add_argument("--remote-debugging-port=9222") chrome_options.add_argument("--user-data-dir=C:/Users/fzh13/Desktop/selenium/cookie") chrome_options.add_argument("--no-sandbox") return if __name__ == "__main__": # 第一次启动(创建新会话) chrome_options = Options() service = webdriver.ChromeService(executable_path='chromedriver.exe')#设置驱动 chrome_options.add_experimental_option("detach", True) # 防止自动关闭 chrome_options.add_argument('--start-maximized')# 最大化 chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])#不显示被控制 chrome_options.add_experimental_option("useAutomationExtension", False)#不显示被控制 driver1 = init_driver(reuse_session=False) driver = webdriver.Chrome(options=chrome_options, service=service) driver1.get("https://www.baidu.com") print("首次会话标题:", driver1.title) time.sleep(2) driver1.quit() # 注意这里会关闭浏览器进程 # 第二次启动(必须手动启动浏览器后连接) # 需先执行命令: chrome --remote-debugging-port=9222 --user-data-dir=./chrome_profile driver2 = init_driver() print("复用会话标题:", driver2.title) driver2.quit() Traceback (most recent call last): File "C:\Users\fzh13\Desktop\selenium\1.py", line 31, in <module> driver1.get("https://www.baidu.com") AttributeError: 'NoneType' object has no attribute 'get'

2025-03-17 上传

from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.webdriver import WebDriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options from selenium.common.exceptions import TimeoutException, WebDriverException from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def init_driver(): chrome_options = Options() # 基础配置 chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("--headless=new") chrome_options.add_argument("--disable-gpu") chrome_options.add_argument("--single-process") # 强化反检测配置 chrome_options.add_argument("--disable-blink-features=AutomationControlled") chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) chrome_options.add_experimental_option('useAutomationExtension', False) # 初始化Driver(确保路径正确) service = Service(executable_path="/usr/bin/sensible-browser") driver: WebDriver = webdriver.Chrome(service=service) # 覆盖WebDriver属性 driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', { 'source': ''' Object.defineProperty(navigator, 'webdriver', { get: () => undefined }); ''' }) return driver # 安全初始化Driver变量 driver = None try: driver = init_driver() driver.get('http://portal.sx.cmcc/home') # 显式等待元素可见(非仅存在) wait = WebDriverWait(driver, 15) main_content = wait.until( EC.visibility_of_element_located((By.ID, "main-content")) ) print("成功加载目标元素!") except TimeoutException as e: print(f"页面元素加载超时: {str(e)}") except WebDriverException as e: print(f"浏览器驱动异常: {str(e)}") if "net::ERR_NAME_NOT_RESOLVED" in str(e): print("提示:请检查网址是否正确或网络连接是否正常") except Exception as e: print(f"未知错误: {str(e)}") finally: if driver: driver.quit() else: print("警告:Driver未成功初始化,无需退出")

2025-03-13 上传
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部