【问题标题】:Python - TypeError: unbound method errorPython - TypeError:未绑定的方法错误
【发布时间】:2016-10-05 22:00:24
【问题描述】:

请帮忙,我是 python 新手,现在遇到错误

"TypeError: 未绑定的方法 assertEqual() 必须以 ExampleScript14 实例作为第一个参数调用(取而代之的是 str 实例)"

以下代码:

从硒导入网络驱动程序 从 selenium.webdriver.common.by 导入 导入单元测试 进口时间 导入变量 从时间导入睡眠

class ExampleScript14(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        super(ExampleScript14, cls).setUpClass()
        cls.driver = webdriver.Chrome()
        cls.driver.get(cls.url)
        cls.test_click_the_username()

    @classmethod
    def test_click_the_username(self):

        # Click the USer name
        self.driver.find_element_by_link_text(variables.USER_NAME).click()

        # click the Edit button
        self.driver.find_element_by_id("btnSave").click()

        print "Verify Edit button changed to Save button"

        element = self.driver.find_element_by_id("btnSave")
        element_attribute = element.get_attribute("value").encode('utf8')
        print "attr:", type(element_attribute)
        print "The button value is:", element_attribute

        self.assertEqual("Save", element_attribute)           

if __name__ == "__main__":
    unittest.main()

【问题讨论】:

  • 错误被追溯到assertEqual(),但您尚未提供该方法的代码。
  • assertEqual() 是一个 selenium 方法,我是从 selenium import webdriver 导入的

标签: python selenium


【解决方案1】:

您的test_click_the_username 不应该是classmethod。只需删除 @classmethod 装饰器,它应该可以工作。

【讨论】:

  • 是的,它有效。但在这里我需要使用类方法。有没有可能用 classmethd 解决这个问题?
猜你喜欢
  • 2011-04-03
  • 2017-11-06
  • 2013-12-25
  • 2011-08-26
  • 1970-01-01
  • 2017-07-19
  • 2016-04-17
  • 2016-09-15
  • 2016-11-30
相关资源
最近更新 更多