Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Facing TypeError:必须使用HomePageTest实例作为第一个参数调用未绑定的方法setUpClass()(但没有得到任何结果)_Python_Selenium - Fatal编程技术网

Python Facing TypeError:必须使用HomePageTest实例作为第一个参数调用未绑定的方法setUpClass()(但没有得到任何结果)

Python Facing TypeError:必须使用HomePageTest实例作为第一个参数调用未绑定的方法setUpClass()(但没有得到任何结果),python,selenium,Python,Selenium,下面是我尝试过的脚本 import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.by import By class HomePageTest (unittest.TestCase): def setUpClass(self): self.driv

下面是我尝试过的脚本

import unittest
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By


class HomePageTest (unittest.TestCase):

    def setUpClass(self):
        self.driver = webdriver.Firefox()
        self.driver.get("http://magento-demo.lexiconn.com/")
        self.driver.maximize_window()

    def test_searchbox(self):
        driver=self
        driver.assertTrue (driver.is_element_present (By.ID,"search"))
        driver.assertTrue (driver.driver.find_element_by_id("search").is_enabled())


    def tearDownClass(self):
     self.driver.quit()

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

if __name__ == '__main__':
  unittest.main(verbosity=2)

您需要创建setUpClass和tearDownClass-classmethods:

@classmethod
def setUpClass(cls):
    ...

@classmethod
def tearDownClass(cls):
    ...