![](/img/trans.png)
[英]TypeError: unbound method “method name” must be called with “Class name” instance as first argument (got str instance instead)
[英]TypeError: unbound method test_logn() must be called with LoginPage instance as first argument (got CompanyManagement instance instead)
(我是python的初学者)我有一个基类。 继承基类,login.py可以正常运行。 但是,当我运行Company_Management.py时,它给我错误TypeError:必须使用LoginPage实例作为第一个参数来调用未绑定方法test_logn()(改为使用CompanyManagement实例)
我想做的是,当我运行Company_Management.py时,它将首先执行test_logn(self)方法,然后单击xpath中的2个URL。
import unittest
from selenium import webdriver
class Login(unittest.TestCase):
@classmethod
def setUpClass(inst):
inst.driver = webdriver.Chrome('/home/sohel/eclipse-workspace/chromedriver')
@classmethod
def tearDownClass(inst):
inst.driver.close()
if __name__ == '__main__':
unittest.main()
import base
import unittest
import time
class LoginPage(base.Login):
def test_logn(self):
driver =self.driver
driver.get("https://www.car.com/login?back_url=%2F")
driver.find_element_by_id("email").clear()
driver.find_element_by_id("email").send_keys("key@gmail.com")
if __name__ == '__main__':
unittest.main()
import base
import unittest
import time
import login
class CompanyManagement(base.Login):
def test_company(self):
driver =self.driver
driver.get("https://www.car.com/login?back_url=%2F")
Login_test = login.LoginPage.test_logn(self)
driver.find_element_by_xpath("//ec-ui-side-bar/div/div/ul/li[3]/a/span").click()
driver.find_element_by_xpath("//ec-ui-side-bar/div/div/ul/li[3]/ul/li/a/span").click()
if __name__ == '__main__':
unittest.main()
在此,在线路Login_test = login.LoginPage.test_logn(self)
, self
代表其所属意味着对象类的对象CompanyManagement
。 这就是为什么在获取错误的got CompanyManagement instance instead)
要调用test_logn
您需要类LoginPage
对象。 您可以这样称呼它:
from login import LoginPage
class CompanyManagement(base.Login):
def test_company(self):
driver =self.driver
driver.get("https://www.car.com/login?back_url=%2F")
Login_test = LoginPage().test_logn()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.