要素の存在を宣言しようとしています。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"))
2つのassert文があります。私は最初の1つを実行する場合、それは正常に動作しますが、私はしたくない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