요소의 존재를 주장하려고 노력 중이며 지금은 원하는대로 작동합니다.AssertTrue가 누락되었습니다. 1 필수 위치 지정 인수입니다.
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 함수를 호출하고 싶습니다. 에
TypeError: is_element_present() missing 1 required positional argument: 'what'
내가 아주 간단한 뭔가를 놓친 거지 알고 ....
'self'를 인수로 취하는 모든 함수는 메소드로 사용됩니다. 그래서 클래스 내부에 있어야하고'instance.method_name()'을 통해 호출되어야합니다. 그것이 클래스에 있어야하는 것이 아니라면, 그것은'self' 매개 변수를 가져서는 안됩니다. – khelwood
'is_element_present_common'을 클래스 안에 넣으려고했는데 같은 에러가 나옵니다. 나는 이미'self' 매개 변수를 제거하려고 시도했으나 다른 오류를 계속 발생 시키므로 구문을 올바로 가져올 수 없습니다 : -'NameError : name 'driver'is not defined – Northers
죄송합니다, 틀린 오류를 넣으십시오. - TypeError : is_element_present_common() missing 1 필수 위치 인수 : 'what''은 원래의 오류 메시지와 동일합니다 ...?!? – Northers