python - Selenium 'dict' 对象没有属性 'to_capabilities'
问题描述
我正在开发一个自动机器人测试项目来抓取和测试 booking.com 网站,我的文件夹结构为
BotScraper
-bookings
- __init__.py
- booking.py
- constants.py
-main.py
main.py 代码
from bookings.booking import Booking
# create instance for Booking class
bot = Booking()
bot.landing_page()
预订.py 代码
import bookings.constants as const
from selenium import webdriver
# Inherited webdriver.Chrome(superclass) w.r.t booking class(child class)
class Booking(webdriver.Chrome(r"C:\SeleniumDrivers\chromedriver.exe")):
# constructor for driver path default is mentioned
def __init__(self, driver_path=r"C:\SeleniumDrivers\chromedriver.exe"):
self.driver_path = driver_path
# webdriver.chrome class methods accessible now
super(Booking, self).__init__()
def landing_page(self):
# self. (all methods for webdriver.chrome now accessible)
self.get(const.TARGET_BASE_URL)
常量.py 代码
TARGET_BASE_URL = "https://www.booking.com"
当我执行 main.py 然后浏览器打开但是,代码停止执行并返回错误
Traceback (most recent call last):
File "C:/Users/wangu/Desktop/Testing_Practices/Selenium/seBotScraper/main.py", line
1, in <module>
from bookings.booking import Booking
File
"C:\Users\wangu\Desktop\Testing_Practices\Selenium\seBotScraper\bookings\booking.py",
line 7, in <module>
class Booking(webdriver.Chrome(r"C:\SeleniumDrivers\chromedriver.exe")):
File "C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64,
in __init__
desired_capabilities = options.to_capabilities()
AttributeError: 'dict' object has no attribute 'to_capabilities'
进程以退出代码 1 结束
知道可能是什么原因导致此错误及其解决方案。
解决方案
推荐阅读
- vue.js - 对 Prop(来自父级)对象的属性进行计算并将结果放入模板中的最佳方法
- google-sheets - 我可以使用第二个条件订购数据透视表吗?
- android - 无法构建,因为框架已经在构建 - Flutter
- amazon-web-services - 架构未与 AWS Glue 爬网程序正确合并
- reactjs - 如何在 React-Router 中传递参数
- python - Python 意外退出访问 cv2.VideoCapture(0)
- javascript - 隐藏在溢出下的下拉菜单:隐藏容器
- android - Flutter 切换开关和共享首选项
- hyperledger-fabric - Hyperledger:对等方不断出现“会员视图已更改。对等方上线/下线”错误
- android - android:windowSoftInputMode="adjustResize" 不适用于 TranslucentTheme 活动