Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用方法getattr Python Selenium_Python_Function_Selenium_Class_Getattr - Fatal编程技术网

调用方法getattr Python Selenium

调用方法getattr Python Selenium,python,function,selenium,class,getattr,Python,Function,Selenium,Class,Getattr,我有以下代码的密码: 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, select

我有以下代码的密码:

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, method, selector, selector2 = 'none'):
        try:
            self.__call_method_from_base_page(method, selector, 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, selector, selector2).send_keys(keys_to_send)
                    break
                except:
                    counter += 1
            if counter == 4:
                raise e
类基本页:
def u u init u u;(self,driver,timeout=10):
self.driver=driver
self.timeout=超时
self.wait=WebDriverWait(self.driver,self.timeout)
从基本页面(self、method、selector、selector2='none')调用方法:
方法调用=getattr(BasePage(self.driver,self.timeout),方法)
如果selector2==“无”:
返回方法\u到\u调用(选择器)
其他:
返回方法\u到\u调用(选择器、选择器2)
def自定义发送键(self、key-to-send、method、selector、selector2='none'):
尝试:
self.\u从基本页面调用方法(方法、选择器、选择器2)。发送键(键到键发送)
除了WebDriverException作为e:
计数器=1
当计数器<4时:
尝试:
打印(“元素”+str(选择器)+“+str(选择器2)+”在“+str(计数器)+”重试中找不到)
self.\u从基本页面调用方法(方法、选择器、选择器2)。发送键(键到键发送)
打破
除:
计数器+=1
如果计数器==4:
提高e
我需要使用自定义\u发送\u键,但我不明白在这种情况下使用的是来自\u基本\u页面的
调用\u方法\u?你知道我如何调用
自定义发送键
函数,以便在上述类和函数之后发送“自定义文本”吗