python - 类型错误:__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()
driver
intest_log()
来自fixtures 方法(confest.py)
解决方案
问题在这里
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
推荐阅读
- regex - 需要正则表达式是非贪婪的
- python - 注释行出现意外的文件结尾错误
- apache-flink - 是否可以使用 Apache Flink 在多台机器上分发 MapState 值?
- neo4j - “此查询在断开连接的模式之间构建笛卡尔积”警告
- php - Hello World PHP 示例,用于存储和读取来自 Google Apps Engine 的免费 Google Cloud Storage 存储桶中的文件
- mysql - INFORMATION_SCHEMA.TABLE_CONSTRAINTS 缺少在 MySQL 中显示为 SHOW INDEX 的索引
- continuous-integration - ML 模型部署 CI/CD
- r - 如何更改跟踪中段的颜色?
- acumatica - 如何在 BQL 中使用“喜欢”
- php - 如何将属性添加到其他数组中的对象?