【发布时间】:2022-01-13 03:10:40
【问题描述】:
我正在尝试为我的 selenium 浏览器创建一个子类。这是我的代码:
class SeleniumDriver:
"""Class that represents a game."""
def __init__(self):
# start Tor browser
self.profile_path = r'C:\Tor Browser2\Browser\TorBrowser\Data\Browser\profile.default'
self.options = Options()
self.options.binary_location = r'C:\Tor Browser2\Browser\firefox.exe'
self.options.set_preference('profile', self.profile_path)
self.service = Service('C:/Utility/BrowserDrivers/geckodriver/geckodriver.exe')
self.driver = Firefox(service=self.service, options=self.options)
class Items(SeleniumDriver):
def __init__(self):
super().__init__()
# More methods that do stuff....
当我初始化这两个类时,子类会启动一个新的浏览器窗口。如何使其附加到现有/父级初始化浏览器?我尝试将“self.driver = Firefox”分离到另一种方法,但随后子类抛出:
AttributeError: 'Item' object has no attribute 'driver'
【问题讨论】:
标签: python selenium class inheritance parent-child