0
2つの異なるpythonファイルの間でパラメータを使用しようとしています。このファイルには2つの異なるPythonファイル内のパラメータを使用する
locators.py
from selenium.webdriver.common.by import By
class MainPageLocatars(object):
ELEMENT = (By.XPATH, "//label[text() = '%s']"%(i))
、私は定義されたi
を持っている:私はロケータを定義したlocators.py
を、持っています。私はこのコードを実行すると
main.py
import locators
from locators import *
from locators import MainPageLocatars
def __selectCheckbox(self, checkbox, locater):
if checkbox == "All":
if self.driver.find_element_by_id(locater).is_selected() == False:
self.execute_script_click(MainPageLocatars.CHECKBOX)
else:
if self.driver.find_element_by_id(locater).is_selected() == False:
self.execute_script_click(MainPageLocatars.CHECKBOX)
self.execute_script_click(MainPageLocatars.CHECKBOX)
elif self.driver.find_element_by_id(locater).is_selected() == True:
self.execute_script_click(MainPageLocatars.CHECKBOX)
for i in checkbox:
# only this element is not defined in locators.py
self.execute_script_click(*MainPageLocatars.ELEMENT)
、私はエラーがi
が定義されていないと言い得ます。私はロケータをインポートしていますが、なぜ動作していないのかわかりません。
:MainPageLocatars.pyあなた
main.py
でそして
:あなたはこのようなファイルを持つことができますループで変数iを使用しています。それからlocatars.pyで私は "i"を使用していますが、テストを実行するときには定義されていません。 – user7242550
@ user7242550 'locators.py'ファイルの設定を試しましたか? –
はい、私のケースではparam1は単なるテキストではないので動作しません。それは私のmain.py – user7242550