的Python /硒函数调用和必需的参数丢失
我已经定义了以下两个功能:的Python /硒函数调用和必需的参数丢失
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 = "[email protected]"
self.pwd = "test"
elif(language == "en"):
self.username = "[email protected]"
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()
当我尝试呼叫建立这样的:
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)
有人可以帮我解决这个问题。我不明白为什么它说失去了一个论点。
在此先感谢您的帮助!
回答:
正如@furas所说,我只是简单地使用了他们在课堂上的功能,但他们不是。
因此,解决办法是删除从参数列表中的自我:
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()
以上是 的Python /硒函数调用和必需的参数丢失 的全部内容, 来源链接: utcz.com/qa/261831.html