-2

任何人都可以請指出什麼是錯在哪我已經實現如下:「NoneType」對象有沒有屬性「功能」

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' 
+2

你至少應該與打印 –

+1

你爲什麼要假定'driver.get'返回一些調試代碼? – DeepSpace

回答

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() 
相關問題