How to use element_find_element method in AutoItDriverServer

Best Python code snippet using AutoItDriverServer_python

server.py

Source:server.py Github

copy

Full Screen

...175@app.route('/wd/hub/session/<session_id>/elements', method='POST')176def find_elements(session_id=''):177 return _find_element(session_id, "wd_frame", many=True)178@app.route('/wd/hub/session/<session_id>/element/<element_id>/element', method='POST')179def element_find_element(session_id='', element_id=''):180 return _find_element(session_id, "elements['%s']" % element_id)181@app.route('/wd/hub/session/<session_id>/element', method='POST')182def find_element(session_id=''):183 return _find_element(session_id, "wd_frame")184def _find_element(session_id, context, many=False):185 try:186 # TODO: need to support more locator_strategy's187 json_request_data = json.loads(request.body.read())188 locator_strategy = json_request_data.get('using')189 value = json_request_data.get('value')190 ios_request = "%s.findElement%sAndSetKey%s('%s')" % (context, 's' if many else ''191 , 's' if many else '', value)192 ios_response = app.ios_client.proxy(ios_request)193 if not many:...

Full Screen

Full Screen

decorators.py

Source:decorators.py Github

copy

Full Screen

1from selenium.common.exceptions import NoSuchElementException2import functools3from time import sleep, monotonic4from .helpers import validate_time_settings5from .recover import RecoverData, RecoverFuncId6def _find_element_next_state(prev_state, time_left, poll_frequency):7 if time_left <= 0:8 if prev_state is None:9 return ("recover_or_raise", 0)10 else:11 return ("raise", None)12 return ("recover_and_retry", min(time_left, poll_frequency))13def find_element(func):14 special_args = ("timeout", "poll_frequency", "recover")15 @functools.wraps(func)16 def find_element_decorator(self, *args, **kwargs):17 func_kwargs = {k: v for (k, v) in kwargs.items() if k not in special_args}18 timeout = kwargs.get("timeout", self.timeout)19 poll_frequency = kwargs.get("poll_frequency", self.poll_frequency)20 recover = kwargs.get("recover", self.recover)21 start_time = monotonic()22 state = None23 attempts = 024 validate_time_settings(self._implicitly_wait, timeout, poll_frequency)25 while True:26 exception = None27 try:28 from .webelement import SeleniousWrapWebElement29 return SeleniousWrapWebElement(func(self, *args, **func_kwargs))30 except NoSuchElementException as e:31 timestamp = monotonic()32 time_left = timeout + start_time - timestamp33 state, sleep_time = _find_element_next_state(34 prev_state=state, time_left=time_left, poll_frequency=poll_frequency35 )36 if state == "raise" or (state == "recover_or_raise" and not recover):37 raise38 exception = e39 attempts += 140 if recover:41 save = self.recover42 self.recover = None43 from .webdriver_mixin import WebDriverMixin44 if isinstance(self, WebDriverMixin):45 webdriver = self46 element = None47 func_id = RecoverFuncId.FIND_ELEMENT48 else:49 webdriver = self.parent50 element = self51 func_id = RecoverFuncId.ELEMENT_FIND_ELEMENT52 recover_data = RecoverData(53 webdriver=webdriver,54 element=element,55 func_id=func_id,56 function=func,57 args=args,58 kwargs=kwargs,59 elapsed=timestamp - start_time,60 attempts=attempts,61 exception=exception,62 )63 try:64 recover(recover_data)65 except: # noqa E72266 self.recover = save67 raise68 self.recover = save69 sleep(sleep_time)70 return find_element_decorator71def _find_elements_next_state(72 prev_state,73 time_left,74 poll_frequency,75 debounce,76 stable_time,77 ismin,78):79 if ismin:80 settle_time_remaining = debounce - stable_time81 if settle_time_remaining > 0:82 return ("debounce", settle_time_remaining)83 else:84 return ("success", None)85 if time_left <= 0:86 if prev_state is None:87 return ("recover_or_raise", 0)88 else:89 return ("raise", None)90 return ("recover_and_retry", min(time_left, poll_frequency))91def find_elements(func):92 special_args = ("timeout", "poll_frequency", "recover", "min", "debounce")93 @functools.wraps(func)94 def find_elements_decorator(self, *args, **kwargs):95 func_kwargs = {k: v for (k, v) in kwargs.items() if k not in special_args}96 timeout = kwargs.get("timeout", self.timeout)97 poll_frequency = kwargs.get("poll_frequency", self.poll_frequency)98 recover = kwargs.get("recover", self.recover)99 min = kwargs.get("min", 0)100 debounce = kwargs.get("debounce", self.debounce)101 debounce = poll_frequency if debounce is True else debounce102 start_time = monotonic()103 attempts = 0104 prev_len = 0105 prev_time = start_time106 state = None107 validate_time_settings(self._implicitly_wait, timeout, poll_frequency)108 while True:109 retval = func(self, *args, **func_kwargs)110 timestamp = monotonic()111 attempts += 1112 length = len(retval)113 if length != prev_len:114 prev_time = timestamp115 prev_len = length116 stable_time = 0117 else:118 stable_time = timestamp - prev_time119 time_left = timeout + start_time - timestamp120 ismin = prev_len >= min121 state, sleep_time = _find_elements_next_state(122 prev_state=state,123 time_left=time_left,124 poll_frequency=poll_frequency,125 debounce=debounce,126 stable_time=stable_time,127 ismin=ismin,128 )129 if state == "success":130 from .webelement import SeleniousWrapWebElement131 return [SeleniousWrapWebElement(e) for e in retval]132 if state == "raise" or (state == "recover_or_raise" and not recover):133 raise NoSuchElementException(134 "{} elements is less than min of {}".format(length, min)135 )136 if state in ("recover_or_raise", "recover_and_retry") and recover:137 save = self.recover138 self.recover = None139 from .webdriver_mixin import WebDriverMixin140 if isinstance(self, WebDriverMixin):141 webdriver = self142 element = None143 func_id = RecoverFuncId.FIND_ELEMENTS144 else:145 webdriver = self.parent146 element = self147 func_id = RecoverFuncId.ELEMENT_FIND_ELEMENTS148 recover_data = RecoverData(149 webdriver=webdriver,150 func_id=func_id,151 function=func,152 element=element,153 args=args,154 kwargs=kwargs,155 elapsed=timestamp - start_time,156 attempts=attempts,157 elements=retval,158 )159 try:160 recover(recover_data)161 except: # noqa E722162 self.recover = save163 raise164 self.recover = save165 sleep(sleep_time)...

Full Screen

Full Screen

recover.py

Source:recover.py Github

copy

Full Screen

1from enum import Enum, auto2class RecoverFuncId(Enum):3 FIND_ELEMENT = auto()4 FIND_ELEMENTS = auto()5 ELEMENT_FIND_ELEMENT = auto()6 ELEMENT_FIND_ELEMENTS = auto()7 ELEMENT_CLICK = auto()8class RecoverData:9 def __init__(10 self,11 webdriver,12 func_id,13 function,14 args,15 kwargs,16 element=None,17 elements=None,18 exception=None,19 attempts=1,20 elapsed=0,21 ):22 self.webdriver = webdriver23 self.func_id = func_id24 self.function = function25 self.args = args26 self.kwargs = kwargs27 self.element = element28 self.elements = elements29 self.exception = exception30 self.attempts = attempts...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run AutoItDriverServer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful