def select(self, **kwargs): self._date_element.select(**kwargs) click_when_enabled( self.driver, self.find_child('ufss-slot-toggle-native-button'), **kwargs )
def select(self, **kwargs): click_when_enabled( self.driver, self.driver.find_element_by_xpath( "//button[contains(@id, 'selector-button-{}')]".format( self.delivery_type.lower() ) ), **kwargs ) self._date_element.select(**kwargs) click_when_enabled(self.driver, self._element, **kwargs)
def navigate_waypoint(self, driver, waypoint, timeout, valid_dest): log.info('Navigating ' + str(waypoint)) elem = wait_for_element(driver, waypoint.locator, timeout=timeout) jitter(.4) click_when_enabled(driver, elem) try: WebDriverWait(driver, timeout).until(EC.staleness_of(elem)) except TimeoutException: pass current = remove_qs(driver.current_url) if current == BASE_URL + waypoint.dest: log.info("Navigated to '{}'".format(waypoint.dest)) elif valid_dest and any(d in current for d in valid_dest): log.info("Navigated to valid dest '{}'".format(current)) else: raise NavigationException("Navigation to '{}' failed".format( waypoint.dest))
def handle_throttle(browser, timeout_mins=10): alert('Throttled', 'Sosumi') # Dump source until we're sure we have correct locator for continue button dump_source(browser.driver) try: click_when_enabled( browser.driver, wait_for_element(browser.driver, browser.Locators.THROTTLE_CONTINUE), timeout=60) except Exception as e: log.error(e) t = datetime.now() while browser.Patterns.THROTTLE_URL in browser.current_url: if int((datetime.now() - t).total_seconds()) > timeout_mins * 60: raise UnhandledRedirect( 'Throttled and timed out waiting for user input') sleep(1)
def navigate_waypoint(self, waypoint, timeout, valid_dest): if callable(waypoint.callable): log.info('Executing {}() before navigation'.format( waypoint.callable.__name__)) waypoint.callable(browser=self) log.info('Navigating ' + str(waypoint)) elem = wait_for_element(self.driver, waypoint.locator, timeout=timeout) jitter(.4) click_when_enabled(self.driver, elem) try: WebDriverWait(self.driver, timeout).until(EC.staleness_of(elem)) except TimeoutException: pass if waypoint.check_current(self.current_url): log.info("Navigated to '{}'".format( waypoint.check_current(self.current_url))) elif valid_dest and any(d in self.current_url for d in valid_dest): log.info("Navigated to valid dest '{}'".format(self.current_url)) else: raise NavigationException("Navigation to '{}' failed".format( waypoint.dest))
def handle_oos(browser, timeout_mins=10): try: browser.save_removed_items() except Exception: log.error('Could not save removed items') if browser.args.ignore_oos: log.warning('Attempting to proceed through OOS alert') click_when_enabled( browser.driver, wait_for_element(browser.driver, browser.Locators.OOS_CONTINUE)) else: t = datetime.now() alert( "An item is out of stock. Press continue if you'd like to proceed", 'Sosumi') while browser.Patterns.OOS_URL in browser.current_url: if int((datetime.now() - t).total_seconds()) > timeout_mins * 60: raise ItemOutOfStock( 'Encountered OOS alert and timed out waiting for user ' 'input\n Use `ignore-oos` to bypass these alerts') sleep(1)
def handle_redirect(driver, ignore_oos, valid_dest=None, timeout=None, route=None): current = remove_qs(driver.current_url) log.warning("Redirected to: '{}'".format(current)) if Patterns.AUTH_URL in current: wait_for_auth(driver) elif Patterns.OOS_URL in current: try: save_removed_items(driver) except Exception: log.error('Could not save removed items') if ignore_oos: log.warning('Attempting to proceed through OOS alert') click_when_enabled(driver, wait_for_element(driver, Locators.OOS_CONTINUE)) else: raise ItemOutOfStock( 'Encountered OOS Alert. Use `ignore-oos` to bypass') elif route and current == route.route_start and route.waypoints_reached: raise RouteRedirect() elif valid_dest and timeout: log.warning( 'Handling unknown redirect (timeout in {}s)'.format(timeout)) try: WebDriverWait(driver, timeout).until(EC.url_matches('|'.join(valid_dest))) except TimeoutException: raise UnhandledRedirect( "Timed out waiting for redirect to a valid dest\n" "Current URL: '{}'".format(driver.current_url)) else: raise UnhandledRedirect()
def select(self, **kwargs): click_when_enabled(self.driver, self._element, **kwargs)
def select(self, **kwargs): click_when_enabled( self.driver, self.find_child(".//input[@type='radio']"), **kwargs )