我试图断言一个元素的存在,我可以让它工作,但现在我想要的方式。
我有一个通用的函数文件:-
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"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句