简体   繁体   English

python wrapper; 正确命名方法调用

[英]python wrapper; correct naming for method calling

I want to wrap the selenium webdriver in my own class, that each time I will call a method from my class it will handle calling and error handling to the webdriver class. 我想将硒webdriver包装在我自己的类中,这样,每次我从类中调用一个方法时,它将处理对webdriver类的调用和错误处理。 what is the correct way to do it ? 正确的方法是什么?

class myClass():
    browser = ... selenium web driver ...
    def find_element_by_xpath(self, value):
        try
            browser.find_element_by_xpath(value)
        except:
            ....

can myClass have the same method name ? myClass可以具有相同的方法名称吗?

There are multiple valid ways to handle the calling and error handling of the webdriver class and yours should be fine. 有多种有效的方法可以处理webdriver类的调用和错误处理,您的方法应该没问题。

Yes, myClass can have the same method names but you need to make sure you're calling the right thing. 是的, myClass可以具有相同的方法名称,但是您需要确保调用正确的方法。 Eg 例如

myClassInstance = myClass()
myClassInstance.find_element_by_xpath('thing')

will call browser.find_element_by_xpath just fine 会很好地调用browser.find_element_by_xpath

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM