'NoneType'对象没有属性'function'

时间:2017-03-12 08:08:33

标签: python selenium selenium-chromedriver ui-automation attributeerror

任何人都可以指出我实施的内容有什么问题如下:

def setUp(self):
    self.driver = selenium.webdriver.Chrome()
    self.page = self.driver.get("http://mywebsite/form")
    self.page.search_trip(2, 2)

def search_trip(self, depart, arrival):
    departing  = Element(Locators.XPATH, "//select[@name='departing']/option[@value='%i']" %depart)
    returning  = Element(Locators.XPATH, "//select[@name='returning']/option[@value='%i']" %arrival)
    search     = Element(Locators.XPATH, "//input[@type='submit']")

    self.departing.click()  
    self.returning.click()
    self.search.submit()

错误代码:

self.page.search_trip(2, 2)
AttributeError: 'NoneType' object has no attribute 'search_trip'

1 个答案:

答案 0 :(得分:0)

drive.get(url)不返回任何内容!和search_trip是一个属于类的方法,而不是self.page对象(这里没有)!

def setUp(self):
    self.driver = selenium.webdriver.Chrome()
    #driver.get() returns None
    self.driver.get("http://mywebsite/form")
    #search_trip is a method inside the class.
    self.search_trip(2, 2)

def search_trip(self, depart, arrival):
    departing  = Element(Locators.XPATH, "//select[@name='departing']/option[@value='%i']" %depart)
    returning  = Element(Locators.XPATH, "//select[@name='returning']/option[@value='%i']" %arrival)
    search     = Element(Locators.XPATH, "//input[@type='submit']")

    self.departing.click()  
    self.returning.click()
    self.search.submit()