如何解决调用方法getattr Python Selenium
我有以下代码:
class BasePage:
def __init__(self,driver,timeout=10):
self.driver = driver
self.timeout = timeout
self.wait = WebDriverWait(self.driver,self.timeout)
def __call_method_from_base_page(self,method,selector,selector2 ='none'):
method_to_call = getattr(BasePage(self.driver,self.timeout),method)
if selector2 == 'none':
return method_to_call(selector)
else:
return method_to_call(selector,selector2)
def custom_send_keys(self,keys_to_send,selector2 = 'none'):
try:
self.__call_method_from_base_page(method,selector2).send_keys(keys_to_send)
except WebDriverException as e:
counter = 1
while counter < 4:
try:
print("Element " + str(selector) + " " + str(selector2) + " couldn't be found in " + str(counter) + " retry.")
self.__call_method_from_base_page(method,selector2).send_keys(keys_to_send)
break
except:
counter += 1
if counter == 4:
raise e
我需要使用custom_send_keys,但是我不明白在这种情况下__call_method_from_base_page
的用途是什么?有什么想法可以调用custom_send_keys
函数,以便它在上述类和函数之后发送“自定义文本”吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。