AssertTrue 缺少 1 个必需的位置参数

AssertTrue missing 1 required positional argument

我正在尝试断言一个元素的存在,我可以让它工作,但现在是我想要的方式。

我有一个常用函数文件:-

from selenium.common.exceptions import NoSuchElementException


def is_element_present_common(self, how, what):
    try:
        self.driver.find_element(by=how, value=what)
    except NoSuchElementException as e:
        return False
    return True

...和我的主文件:-

import unittest
from Common import common_functions, initialisation, login
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.common.exceptions import NoSuchElementException


class QuickTestPlanLogin(unittest.TestCase):
    def setUp(self):
        self.driver = initialisation.start_webdriver()
        self.driver = initialisation.start_sap(self.driver)

    def tearDown(self):
        self.driver.close()

    def is_element_present(self, how, what):
        try:
            self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e:
            return False
        return True

    def test_login(self):
        wait = initialisation.wait_for(self.driver)
        self.driver = login.default_login(self.driver, "username", "password")

        # self.assertTrue(self.is_element_present(By.ID, "my-projects-table_info"))
        # self.assertTrue(common_functions.is_element_present_common(By.ID, "my-projects-table_info"))

有两个断言语句。如果我 运行 第一个它工作正常,但它正在调用我不想要的 is_element_present 函数。我想从 common_functions 文件中调用 is_element_present_common 函数。每次我 运行 第二个 assert 语句时,我都会收到以下错误:-

TypeError: is_element_present() missing 1 required positional argument: 'what'

我知道我遗漏了一些非常简单的东西....

将函数定义更改为:

def is_element_present_common(how, what):

将对 is_element_present_common 函数的调用更改为:

self.assertTrue(common_functions.is_element_present_common(By.ID, "my-projects-table_info"))