可重用的WebDriverWait问题“对象没有属性'驱动程序'”

时间:2019-11-17 20:26:23

标签: python selenium selenium-webdriver

我正在尝试创建可重用的Wait,但始终收到此错误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)

1 个答案:

答案 0 :(得分:0)

wait_for可能是这样

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

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