Selenium源码通读·webdriver/common/desired_capabilities.py-DesiredCapabilities类分析

75 篇文章 ¥59.90 ¥99.00
本文深入分析Selenium的DesiredCapabilities类,探讨其在定义和管理WebDriver配置及能力中的作用。从源代码层面,介绍如何初始化、合并能力集以及处理Firefox和Internet Explorer的选项。了解这一关键类有助于更好地使用Selenium框架。

DesiredCapabilities是Selenium中的一个重要类,它用于定义和管理WebDriver的各种配置和期望的能力。在这篇文章中,我们将对DesiredCapabilities类进行详细分析,并深入了解其源代码。

DesiredCapabilities类位于selenium.webdriver.common.desired_capabilities模块中。让我们从源代码中的导入语句开始:

from selenium.webdriver.common import utils

我们首先导入了utils模块。这个模块包含了一些常用的工具函数,用于在Selenium中处理各种实用功能。

接下来,我们来看一下DesiredCapabilities类的定义:

class DesiredCapabilities(object
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[2], line 1 ----> 1 from selenium import webdriver 2 from selenium.webdriver.common.by import By 3 from selenium.webdriver.common.keys import Keys File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\__init__.py:20 18 from selenium.webdriver.chrome.options import Options as ChromeOptions # noqa 19 from selenium.webdriver.chrome.service import Service as ChromeService # noqa ---> 20 from selenium.webdriver.chrome.webdriver import WebDriver as Chrome # noqa 21 from selenium.webdriver.common.action_chains import ActionChains # noqa 22 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # noqa File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chrome\webdriver.py:21 19 from selenium.webdriver.chrome.options import Options 20 from selenium.webdriver.chrome.service import Service ---> 21 from selenium.webdriver.chromium.webdriver import ChromiumDriver 22 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 25 class WebDriver(ChromiumDriver): File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\chromium\webdriver.py:24 22 from selenium.webdriver.common.driver_finder import DriverFinder 23 from selenium.webdriver.remote.command import Command ---> 24 from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver ... ---> 23 from typing_extensions import Sentinel 25 from selenium.webdriver.common.bidi.common import command_builder 26 from selenium.webdriver.common.bidi.session import Session ImportError: cannot import name 'Sentinel' from 'typing_extensions' (C:\Users\d00003591\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\typing_extensions.py) Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
最新发布
12-11
/home/langchao/Desktop/pyautogui文件夹/测试.py:10: DeprecationWarning: Firefox will soon stop logging to geckodriver.log by default; Specify desired logs with log_output service = Service('/usr/local/bin/geckodriver') Traceback (most recent call last): File "/home/langchao/Desktop/pyautogui文件夹/测试.py", line 14, in <module> driver = webdriver.Firefox(service=service, options=options) File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 67, in __init__ super().__init__(command_executor=executor, options=options) File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 206, in __init__ self.start_session(capabilities) File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 290, in start_session response = self.execute(Command.NEW_SESSION, caps)["value"] File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute self.error_handler.check_response(response) File "/home/langchao/PycharmProjects/pythonProject1/.venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
07-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值