我定义了以下两个函数:
def setUp(self, language):
#defines the webdriver
self.browser = webdriver.Firefox()
#calls the website
self.browser.get("http://www.test.com")
#defines the language to be used
self.INTERFACE_LANGUAGE = language
if(language == "de"):
self.username = "testDE@gmail.com"
self.pwd = "test"
elif(language == "en"):
self.username = "testEN@gmail.com"
self.pwd = "test"
return self.username, self.pwd
和
def login_user(self, username, pwd):
"""login the user"""
#fill in the userdata
self.u_Name = self.browser.find_element_by_id("form_user_id")
self.u_Name.send_keys(username)
self.u_Pwd = self.browser.find_element_by_id("form_user_pwd")
self.u_Pwd.send_keys(pwd)
#submit the form
self.submit_Login = self.browser.find_element(By.XPATH,'//input[@name="send" and @value="Log in"]')
self.submit_Login.click()
当我尝试像这样调用setUp时:
lang = "de"
username, pwd = setUp(lang)
login_user(username, pwd)
它返回:
Traceback (most recent call last):
File "c:\Users\user\Documents\test\test.py", line 40, in <module>
username, pwd = setUp(lang)
TypeError: setUp() missing 1 required positional argument: 'language'
login_user(username, pwd)
有人可以帮我解决这个问题。我不明白为什么它说缺少一个论点。
提前感谢您的帮助!
答案 0 :(得分:0)
正如@furas所说,我只是在课堂上使用这些功能,但事实并非如此。
所以解决方法是从参数列表中删除self:
def setUp(language):
#defines the webdriver
global browser, INTERFACE_LANGUAGE
browser = webdriver.Firefox()
#calls the website
browser.get("http://www.test.com")
#defines the language to be used
INTERFACE_LANGUAGE = language
if(language == "de"):
username = "test"
pwd = "test"
elif(language == "en"):
username = "test"
pwd = "test"
return username, pwd
def login_user(username, pwd):
"""login the user to their account"""
#fill in the userdata
u_Name = browser.find_element_by_id("form_user_id")
u_Name.send_keys(username)
u_Pwd = browser.find_element_by_id("form_user_pwd")
u_Pwd.send_keys(pwd)
#submit the form
submit_Login = browser.find_element(By.XPATH,'//input[@name="send" and @value="Log in"]')
submit_Login.click()