【问题标题】:Reusable WebDriverWait problem "object has no attribute 'driver'"可重用 WebDriverWait 问题“对象没有属性‘驱动程序’”
【发布时间】:2019-11-18 09:51:44
【问题描述】:

我正在尝试创建一个可重复使用的等待,但不断收到此错误 WebDriverWait(self.driver, 10).until( AttributeError: 'str' object has no attribute 'driver'

我的代码:

在 Browser.Py 我有

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Browser(object):

 def wait_for(self, locator):
     WebDriverWait(self.driver, 10).until(
     EC.presence_of_element_located(locator))

我尝试通过以下方式调用它:

from features.browser import Browser
from features.locators import Locators
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

class Steps(Browser):

    def delete_from_cart2(self):
        Browser.wait_for(*Locators.DELETE_FROM_CART2)

【问题讨论】:

  • self.driver没有在任何地方定义?

标签: python selenium selenium-webdriver


【解决方案1】:

wait_for可能是这样的

def wait_for(self, driver, locator):
    WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(locator))

驱动实例可以传递给变量。

【讨论】:

    猜你喜欢
    • 2020-12-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    相关资源
    最近更新 更多