Python:将类实例传递给外部函数

时间:2017-04-01 22:36:57

标签: python function instance external

我将类实例传递给外部函数时遇到问题。

from selenium import webdriver
from time import sleep

import time    

class browser(object):

    def __init__(self):
        DEBUG("xxx")
        self.driver = webdriver.Chrome() 
        self.driver.set_page_load_timeout(10)
        DEBUG("xx: Opening browser success")
        DEBUG("xxx: Opening web page xxx")
        self.driver.get("xxxxxxxxxx") 

    def find_element(self,element): ###### Search element in Selenium by all types
        try:
            var = self.driver.find_element_by_partial_link_text(element)
            DEBUG("Find Element: Element by text link " + element + " found")
            return var
        except AttributeError:
            print ("errr")
        except:
            raise Error("Error in Find Element","no-element-" + element ,self)
        else:
            print("xxx")
    def sclik(self,element):
        self.find_element(element).click()
        DEBUG("Click on "+ element )   

# Class Error: take screen,log error
class Error(Exception):
    def __init__(self,func,errorname,object1):
        pass

def DEBUG(message):
    pass
def Login(x,y):
    x.sclik(y)

gra = browser()
Login(gra,"f")

我怎样才能通过" self"实例gra到func函数?

  

TypeError:sclik()只需要2个参数(给定1个)

0 个答案:

没有答案