我试图在两个不同的python文件之间使用一个参数。我有locators.py
,在这里我定义了定位器:
定位器.py
from selenium.webdriver.common.by import By
class MainPageLocatars(object):
ELEMENT = (By.XPATH, "//label[text() = '%s']"%(i))
在这个文件中,我定义了i
。你知道吗
主.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
未定义。我正在导入定位器,但不知道为什么它不工作。你知道吗
在一个类中,你不需要有你想要的值。你可以有这样一个文件:
主页locatars.py
然后在你的
main.py
:相关问题 更多 >
编程相关推荐