Python selenium.common.exceptions.TimeoutException() Examples
The following are 30
code examples of selenium.common.exceptions.TimeoutException().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.common.exceptions
, or try the search function
.
Example #1
Source File: page_element.py From toolium with Apache License 2.0 | 8 votes |
def wait_until_visible(self, timeout=None): """Search element and wait until it is visible :param timeout: max time to wait :returns: page element instance """ try: self.utils.wait_until_element_visible(self, timeout) except TimeoutException as exception: parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else '' msg = "Page element of type '%s' with locator %s%s not found or is not visible after %s seconds" timeout = timeout if timeout else self.utils.get_explicitly_wait() self.logger.error(msg, type(self).__name__, self.locator, parent_msg, timeout) exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg, timeout)) raise exception return self
Example #2
Source File: activities.py From python-client with Apache License 2.0 | 6 votes |
def wait_activity(self: T, activity: str, timeout: int, interval: int = 1) -> bool: """Wait for an activity: block until target activity presents or time out. This is an Android-only method. Args: activity: target activity timeout: max wait time, in seconds interval: sleep interval between retries, in seconds Returns: `True` if the target activity is shown """ try: WebDriverWait(self, timeout, interval).until( lambda d: d.current_activity == activity) return True except TimeoutException: return False # pylint: disable=protected-access # noinspection PyProtectedMember
Example #3
Source File: exe.py From ScreenShooter with MIT License | 6 votes |
def makeScreen(name, url, driver): try: driver.get(url) screenshot = driver.save_screenshot(basename + '/' + str(name) + '.png') appendHTML(name, url) print('[-] Screenshooted: ' + url) return True except UnexpectedAlertPresentException as e: print('[!] Error: ' + str(e)) err.append(url) return False except TimeoutException as t: print('[!] Timeout: ' + str(t)) err.append(url) return False
Example #4
Source File: ConnectionScraper.py From scrape-linkedin-selenium with MIT License | 6 votes |
def get_first_connections(self): try: see_connections_link = WebDriverWait(self.driver, self.timeout).until(EC.presence_of_element_located(( By.CSS_SELECTOR, '.pv-top-card-v2-section__link--connections' ))) except TimeoutException as e: print("""Took too long to load connections link. This usually indicates you were trying to scrape the connections of someone you aren't connected to.""") return [] see_connections_link.click() try: self.configure_connection_type() except TimeoutException: return [] all_conns = []
Example #5
Source File: CompanyScraper.py From scrape-linkedin-selenium with MIT License | 6 votes |
def load_initial(self, company): url = 'https://www.linkedin.com/company/{}'.format(company) self.driver.get(url) try: myElem = WebDriverWait(self.driver, self.timeout).until(AnyEC( EC.presence_of_element_located( (By.CSS_SELECTOR, '.organization-outlet')), EC.presence_of_element_located( (By.CSS_SELECTOR, '.error-container')) )) except TimeoutException as e: raise ValueError( """Took too long to load company. Common problems/solutions: 1. Invalid LI_AT value: ensure that yours is correct (they update frequently) 2. Slow Internet: increase the timeout parameter in the Scraper constructor""") try: self.driver.find_element_by_css_selector('.organization-outlet') except: raise ValueError( 'Company Unavailable: Company link does not match any companies on LinkedIn')
Example #6
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 6 votes |
def get_last_seen(self, name, timeout=10): search = self.browser.find_element_by_css_selector("._3FRCZ") search.send_keys(name+Keys.ENTER) # we will send the name to the input key box last_seen_css_selector = "._315-i" start_time = dt.datetime.now() try: WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located( (By.CSS_SELECTOR, last_seen_css_selector))) while True: last_seen = self.browser.find_element_by_css_selector(last_seen_css_selector).text if last_seen and "click here" not in last_seen: return last_seen end_time = dt.datetime.now() elapsed_time = (end_time-start_time).seconds if elapsed_time > 10: return "None" except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException: return "None" except Exception: return "None" # This method does not care about anything, it sends message to the currently active chat # you can use this method to recursively send the messages to the same person
Example #7
Source File: test_driver_utils.py From toolium with Apache License 2.0 | 6 votes |
def test_wait_until_first_element_is_found_timeout(driver_wrapper, utils): # Configure driver mock driver_wrapper.driver.find_element.side_effect = NoSuchElementException('Unknown') element_locator = (By.ID, 'element_id') start_time = time.time() with pytest.raises(TimeoutException) as excinfo: utils.wait_until_first_element_is_found([element_locator]) end_time = time.time() assert 'None of the page elements has been found after 10 seconds' in str(excinfo.value) # find_element has been called more than one time driver_wrapper.driver.find_element.assert_called_with(*element_locator) # Execution time must be greater than timeout assert end_time - start_time > 10
Example #8
Source File: webdriver.py From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License | 6 votes |
def scan_webdriver(self): self.browser.get(self.entry_url) try: WebDriverWait(self.browser, 30).until( EC.presence_of_element_located((By.TAG_NAME, "body")) ) except TimeoutException as e: messages.error(self.request, e) self.browser.delete_all_cookies() self.browser.add_cookie(self.wtm_cookie) self.browser.add_cookie(self.wtm_debug_cookie) self.browser.get(self.entry_url) for cookie in self.browser.get_cookies(): self.process_webdriver_cookie(cookie) self.browser.quit()
Example #9
Source File: bots.py From Dallinger with MIT License | 6 votes |
def sign_off(self): """Submit questionnaire and finish. This uses Selenium to click the submit button on the questionnaire and return to the original window. """ try: logger.info("Bot player signing off.") feedback = WebDriverWait(self.driver, 20).until( EC.presence_of_element_located((By.ID, "submit-questionnaire")) ) self.complete_questionnaire() feedback.click() logger.info("Clicked submit questionnaire button.") self.driver.switch_to_window(self.driver.window_handles[0]) self.driver.set_window_size(1024, 768) logger.info("Switched back to initial window.") return True except TimeoutException: logger.error("Error during experiment sign off.") return False
Example #10
Source File: driver_utils.py From toolium with Apache License 2.0 | 6 votes |
def wait_until_first_element_is_found(self, elements, timeout=None): """Search list of elements and wait until one of them is found :param elements: list of PageElements or element locators as a tuple (locator_type, locator_value) to be found sequentially :param timeout: max time to wait :returns: first element found :rtype: toolium.pageelements.PageElement or tuple :raises TimeoutException: If no element in the list is found after the timeout """ try: return self._wait_until(self._expected_condition_find_first_element, elements, timeout) except TimeoutException as exception: msg = 'None of the page elements has been found after %s seconds' timeout = timeout if timeout else self.get_explicitly_wait() self.logger.error(msg, timeout) exception.msg += "\n {}".format(msg % timeout) raise exception
Example #11
Source File: page_element.py From toolium with Apache License 2.0 | 6 votes |
def wait_until_clickable(self, timeout=None): """Search element and wait until it is clickable :param timeout: max time to wait :returns: page element instance """ try: self.utils.wait_until_element_clickable(self, timeout) except TimeoutException as exception: parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else '' msg = "Page element of type '%s' with locator %s%s not found or is not clickable after %s seconds" timeout = timeout if timeout else self.utils.get_explicitly_wait() self.logger.error(msg, type(self).__name__, self.locator, parent_msg, timeout) exception.msg += "\n {}".format(msg % (type(self).__name__, self.locator, parent_msg, timeout)) raise exception return self
Example #12
Source File: test_wait_until.py From selenium-python-helium with MIT License | 5 votes |
def test_wait_until_lambda_expires(self): with self.assertRaises(TimeoutException): wait_until(lambda: False, timeout_secs=1)
Example #13
Source File: ssodriver.py From aws-sso with Apache License 2.0 | 5 votes |
def check_alert(self): try: wait = WebDriverWait(self._driver, 1, poll_frequency=self._poll_frequency) alert = wait.until(EC.presence_of_element_located((By.ID, 'alertFrame'))) error = alert.find_element_by_css_selector('div.a-alert-error > div.a-box-inner > h4').text message = alert.find_element_by_css_selector('div.a-alert-error > div.a-box-inner > div.gwt-Label').text raise AlertMessage(f'{error}: {message}') except (TimeoutException, NoSuchElementException): pass
Example #14
Source File: ssodriver.py From aws-sso with Apache License 2.0 | 5 votes |
def refresh_token(self, username, password, restore=False): self.get() self.login(username, password) try: return self.get_token(restore) except TimeoutException: self.check_alert() self.check_mfa()
Example #15
Source File: wrapper.py From QuestradeAPI_PythonWrapper with Apache License 2.0 | 5 votes |
def login(): browser = webdriver.Chrome(os.path.join(os.path.abspath(os.path.dirname(__file__)),'chromedriver.exe')) token = {} browser.get(authorization_url) try: # Wait on the login Submit button to appear WebDriverWait(browser, 30).until( EC.visibility_of_element_located((By.ID, 'ctl00_DefaultContent_btnContinue')) ) # Find the username and password input fields inputElem_username = browser.find_element_by_id('ctl00_DefaultContent_txtUsername') inputElem_password = browser.find_element_by_id('ctl00_DefaultContent_txtPassword') # Populate the username and input fields inputElem_username.send_keys(username) inputElem_password.send_keys(password) # Wait on the Authorization Allow button to appear WebDriverWait(browser, 60).until( EC.visibility_of_element_located((By.ID, 'ctl00_DefaultContent_btnAllow')) ) # Wait on the Authentication Token JSON to appear jsonElement = WebDriverWait(browser, 30).until( EC.presence_of_element_located((By.TAG_NAME, 'pre')) ) token = json.loads(jsonElement.text) __store_token__(jsonElement.text) except TimeoutException: print('Time expired while attempting to login') finally: browser.quit() return token
Example #16
Source File: ikun_basketball.py From learn_python3_spider with MIT License | 5 votes |
def next_page(page_num): try: print('获取下一页数据') next_btn = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.next > button'))) next_btn.click() WAIT.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.active > button'), str(page_num))) get_source() except TimeoutException: browser.refresh() return next_page(page_num)
Example #17
Source File: ikun_basketball.py From learn_python3_spider with MIT License | 5 votes |
def search(): try: print('开始访问b站....') browser.get("https://www.bilibili.com/") # 被那个破登录遮住了 # index = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#primary_menu > ul > li.home > a"))) # index.click() input = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#nav_searchform > input"))) submit = WAIT.until(EC.element_to_be_clickable( (By.XPATH, '/html/body/div[2]/div/div[1]/div[1]/div/div[2]/div/form/div/button'))) input.send_keys('蔡徐坤 篮球') submit.click() # 跳转到新的窗口 print('跳转到新窗口') all_h = browser.window_handles browser.switch_to.window(all_h[1]) get_source() total = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, "#all-list > div.flow-loader > div.page-wrap > div > ul > li.page-item.last > button"))) return int(total.text) except TimeoutException: return search()
Example #18
Source File: caixukun.py From Python-Code with MIT License | 5 votes |
def next_page(page_num): try: print('获取下一页数据') next_btn = WAIT.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#server-search-app > div.contain > div.body-contain > div > div.page-wrap > div > ul > li.page-item.next > button'))) next_btn.click() WAIT.until(EC.text_to_be_present_in_element((By.CSS_SELECTOR, '#server-search-app > div.contain > div.body-contain > div > div.page-wrap > div > ul > li.page-item.active > button'),str(page_num))) get_source() except TimeoutException: browser.refresh() return next_page(page_num)
Example #19
Source File: noip-renew.py From noip-renew with Apache License 2.0 | 5 votes |
def open_hosts_page(self): self.logger.log(f"Opening {Robot.HOST_URL}...") try: self.browser.get(Robot.HOST_URL) except TimeoutException as e: self.browser.save_screenshot("timeout.png") self.logger.log(f"Timeout: {str(e)}")
Example #20
Source File: ssodriver.py From aws-sso with Apache License 2.0 | 5 votes |
def check_mfa(self): try: wait = WebDriverWait(self._driver, 1, poll_frequency=self._poll_frequency) mfa = wait.until(EC.presence_of_element_located((By.ID, 'mfa_form'))) raise MFACodeNeeded(mfa) except TimeoutException: pass
Example #21
Source File: ProfileScraper.py From scrape-linkedin-selenium with MIT License | 5 votes |
def load_profile_page(self, url='', user=None): """Load profile page and all async content Params: - url {str}: url of the profile to be loaded Raises: ValueError: If link doesn't match a typical profile url """ if user: url = 'http://www.linkedin.com/in/' + user if 'com/in/' not in url and 'sales/gmail/profile/proxy/' not in url: raise ValueError( "Url must look like... .com/in/NAME or... '.com/sales/gmail/profile/proxy/EMAIL") self.driver.get(url) # Wait for page to load dynamically via javascript try: myElem = WebDriverWait(self.driver, self.timeout).until(AnyEC( EC.presence_of_element_located( (By.CSS_SELECTOR, self.MAIN_SELECTOR)), EC.presence_of_element_located( (By.CSS_SELECTOR, self.ERROR_SELECTOR)) )) except TimeoutException as e: raise ValueError( """Took too long to load profile. Common problems/solutions: 1. Invalid LI_AT value: ensure that yours is correct (they update frequently) 2. Slow Internet: increase the time out parameter in the Scraper constructor 3. Invalid e-mail address (or user does not allow e-mail scrapes) on scrape_by_email call """) # Check if we got the 'profile unavailable' page try: self.driver.find_element_by_css_selector(self.MAIN_SELECTOR) except: raise ValueError( 'Profile Unavailable: Profile link does not match any current Linkedin Profiles') # Scroll to the bottom of the page incrementally to load any lazy-loaded content self.scroll_to_bottom()
Example #22
Source File: engine.py From NoXss with MIT License | 5 votes |
def run(self): blocked_urls = [] if self.browser == 'chrome': browser = chrome() elif self.browser=='chrome-headless': browser=chrome(headless=True) else: browser = phantomjs() # add cookie, the scope is case_list[0].url's top-domain add_cookie(browser, case_list[0].url) for case in self.case_list: if case.method == 'POST': continue vul = case.vul url = case.url args = case.args splited = url.split('/', 3) path = '/'.join(splited) # if not block if path not in blocked_urls: try: browser.get(url) except TimeoutException, e: print e # mark if browser get() exception REQUEST_ERROR.append(('Openner get()', url, 'timeout')) # browser blocked sometimes. rtn = self.handle_block(browser) if rtn is not None: browser = rtn splited = url.split('/', 3) path = '/'.join(splited) blocked_urls.append(path) except BadStatusLine, e: print e REQUEST_ERROR.append(('Render get()', url, 'BadStatusLine')) splited = url.split('/', 3) path = '/'.join(splited) blocked_urls.append(path) except UnicodeDecodeError: pass
Example #23
Source File: webdriver_util.py From webdriver-python with Apache License 2.0 | 5 votes |
def _wrapper(self, method, message, timeout, caller_frame, func): caller = stack()[caller_frame][3] print("Waiting in {}(), timeout {} secs...".format(caller, timeout)) start = time() try: func(method, message) print("Spent {0:.3f} secs".format(time() - start)) self.shoot(caller) except TimeoutException as e: print('timeout-exception') self.shoot('timeout-exception') raise e
Example #24
Source File: test_wait_until.py From selenium-python-helium with MIT License | 5 votes |
def test_wait_until_lambda_with_driver_expires(self): with self.assertRaises(TimeoutException): wait_until(lambda driver: False, timeout_secs=0.1)
Example #25
Source File: apw_internal.py From tir with MIT License | 5 votes |
def CloseAlert(self): ''' Method to close an alert ''' try: aviso = self.wait aviso.until(EC.alert_is_present()) alert = self.driver.switch_to.alert alert.accept() except TimeoutException: time.sleep(0.5)
Example #26
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 5 votes |
def get_status(self, name): search = self.browser.find_element_by_css_selector("._3FRCZ") search.send_keys(name+Keys.ENTER) # we will send the name to the input key box try: group_xpath = "/html/body/div/div/div/div[3]/header/div[1]/div/span/img" click_menu = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located( (By.XPATH, group_xpath))) click_menu.click() except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException: return "None" except Exception: return "None" try: status_css_selector = ".drawer-section-body > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)" # This is the css selector for status WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located( (By.CSS_SELECTOR, status_css_selector))) status = self.browser.find_element_by_css_selector(status_css_selector).text # We will try for 100 times to get the status for i in range(10): if len(status) > 0: return status else: time.sleep(1) # we need some delay return "None" except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException: return "None" except Exception: return "None" # to get the last seen of the person
Example #27
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 5 votes |
def participants_count_for_group(self, group_name): search = self.browser.find_element_by_css_selector("._3FRCZ") search.send_keys(group_name+Keys.ENTER) # we will send the name to the input key box # some say this two try catch below can be grouped into one # but I have some version specific issues with chrome [Other element would receive a click] # in older versions. So I have handled it spereately since it clicks and throws the exception # it is handled safely try: click_menu = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located( (By.CSS_SELECTOR, "._19vo_ > span:nth-child(1)"))) click_menu.click() except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException as e: return "None" except Exception as e: return "None" current_time = dt.datetime.now() participants_selector = "div._2LSbZ:nth-child(5) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1)" while True: try: participants_count = self.browser.find_element_by_css_selector(participants_selector).text if "participants" in participants_count: return participants_count except Exception as e: pass new_time = dt.datetime.now() elapsed_time = (new_time - current_time).seconds if elapsed_time > self.timeout: return "NONE" # This method is used to get all the participants
Example #28
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 5 votes |
def send_message(self, name, message): message = self.emojify(message) # this will emojify all the emoji which is present as the text in string search = self.browser.find_element_by_css_selector("._3FRCZ") search.send_keys(name+Keys.ENTER) # we will send the name to the input key box try: send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located( (By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]"))) messages = message.split("\n") for msg in messages: send_msg.send_keys(msg) send_msg.send_keys(Keys.SHIFT+Keys.ENTER) send_msg.send_keys(Keys.ENTER) return True except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException: return False except Exception: return False # This method will count the no of participants for the group name provided
Example #29
Source File: async_driver.py From WebWhatsapp-Wrapper with MIT License | 5 votes |
def wait_for_login(self, timeout=90): for _ in range(timeout // 2): try: return await self._run_async(self._driver.wait_for_login, timeout=1) except TimeoutException: await sleep(1) raise TimeoutException("Timeout: Not logged")
Example #30
Source File: engine.py From NoXss with MIT License | 5 votes |
def run(self): blocked_urls = [] if self.browser == 'chrome': browser = chrome() elif self.browser=='chrome-headless': browser=chrome(headless=True) else: browser = phantomjs() # add cookie, the scope is url_list[0]'s top-domain add_cookie(browser, self.url_list[0]) for url in self.url_list: splited = url.split('/', 3) path = '/'.join(splited) # if not block if path not in blocked_urls: try: browser.get(url) except TimeoutException, e: print e # save if browser get() exception REQUEST_ERROR.append(('Render get()', url, 'timeout')) # browser blocks sometimes. rtn = self.handle_block(browser) if rtn is not None: browser = rtn splited = url.split('/', 3) path = '/'.join(splited) blocked_urls.append(path) except BadStatusLine, e: print e REQUEST_ERROR.append(('Render get()', url, 'BadStatusLine')) splited = url.split('/', 3) path = '/'.join(splited) blocked_urls.append(path) except UnicodeDecodeError: pass