首页 > 解决方案 > 类型错误:__init__() 缺少 1 个必需的位置参数:“超时”

问题描述

我正在尝试为一个基本项目运行一些基本测试用例,但是尽管初始化了超类构造函数,我还是收到了这个错误。下面是我的代码。

主页.py

class home(Pages):
    user = (By.NAME, "user-name")
    utxt = "standard_user"
    pwd = (By.ID, "password")
    ptxt = "secret_sauce"
    logbtn = (By.NAME, "login-button")
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)
    def logg(self):
        pg=Pages(self.driver)
        pg.type(self.user,self.utxt)
        pg.type(self.pwd,self.ptxt)
        pg.click1(self.logbtn)`

GenricFun.py

class Pages:
    def __init__(self,driver):
        self.driver=driver

    def click1(self,locator):
        WebDriverWait(self.driver).until(e.visibility_of_element_located(locator)).click()

    def type(self,locator,txt):
       WebDriverWait(self.driver).until((e.visibility_of_element_located(locator))).send_keys(txt)`

测试日志.py

 class Test_log(TestBase):
    def test_log(self):
        self.driver.get("https://www.saucedemo.com/")
        L=home(self.driver)
        L.logg()

driverintest_log()来自fixtures 方法(confest.py)

标签: pythonpython-3.xselenium-webdriverpytest

解决方案


问题在这里

def click1(self,locator):
        WebDriverWait(self.driver).until(e.visibility_of_element_located(locator)).click()

您缺少括号 (),请使用以下代码:

def click1(self,locator):
        WebDriverWait(self.driver).until((e.visibility_of_element_located(locator))).click()

更新 :

等效的语句是:

user = (By.NAME, "user-name")
WebDriverWait(driver).until(EC.visibility_of_element_located(user)).click()

所以上面定义的方法应该是这样的:

def click1(self, locator):
    WebDriverWait(self.driver).until(EC.visibility_of_element_located(locator)).click()


def type(self, locator, txt):
    WebDriverWait(self.driver).until(EC.visibility_of_element_located(locator)).send_keys(txt)

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

推荐阅读