Python selenium.webdriver.support.expected_conditions.alert_is_present() Examples
The following are 18
code examples of selenium.webdriver.support.expected_conditions.alert_is_present().
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.webdriver.support.expected_conditions
, or try the search function
.
Example #1
Source File: xss.py From AutoTriageBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testPOSTXSSDriver(url: str, cookies: Mapping[str, str], data: Mapping[str, str], driver: webdriver) -> \ Optional[str]: """ If the given URL pops an alert box when accessed with the given cookies, return the contents of the alert box, otherwise return None """ driver.setCookies(url, cookies) try: driver.post(url, data) WebDriverWait(driver, config.timeout).until(expected_conditions.alert_is_present()) # Note that despite the name switch_to_alert also handles prompt: # - http://selenium-python.readthedocs.io/navigating.html#popup-dialogs alert = driver.switch_to_alert() text = alert.text driver.reset() return text except (TimeoutException, URLError): driver.reset() return None
Example #2
Source File: scanner.py From traxss with MIT License | 6 votes |
def html_scanner(self, payload, webelement_list, target_url): for id in webelement_list: try: if id.tag_name == 'textarea' or id.tag_name == 'input': id.send_keys(payload) WebDriverWait(self.driver, 1).until(expected_conditions.alert_is_present()) self.driver.switch_to.alert.accept() if self.count_results(self.raw_params, target_url, "HTML Injection"): self.driver.quit() self.final_report() if id.tag_name == 'button' or id.tag_name == 'input': id.click() WebDriverWait(self.driver, 1).until(expected_conditions.alert_is_present()) self.driver.switch_to.alert.accept() if self.count_results(self.raw_params, target_url, "HTML Injection"): self.driver.quit() self.final_report() except TimeoutException: pass except StaleElementReferenceException: pass except ElementNotInteractableException: pass
Example #3
Source File: scanner.py From traxss with MIT License | 6 votes |
def query_scanner(self, payload): for param in self.params.keys(): previous_value = self.params[param] self.params[param] = payload target_url = encode_url(self.base_url, self.params) self.raw_params = urllib.parse.urlencode(self.params) if self.cookies: self.driver.get(self.url) self.driver.add_cookie(self.cookies) self.driver.get(target_url) try: WebDriverWait(self.driver, 1).until(expected_conditions.alert_is_present()) self.driver.switch_to.alert.accept() if self.count_results(self.raw_params, target_url, "URL Query"): self.driver.quit() self.final_report() except TimeoutException: pass
Example #4
Source File: xss.py From AutoTriageBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testGETXSSDriver(url: str, cookies: Mapping[str, str], driver: webdriver) -> Optional[str]: """ If the given URL pops an alert box when accessed with the given cookies, return the contents of the alert box, otherwise return None """ driver.setCookies(url, cookies) try: driver.get(url) WebDriverWait(driver, config.timeout).until(expected_conditions.alert_is_present()) # Note that despite the name switch_to_alert also handles prompt: # - http://selenium-python.readthedocs.io/navigating.html#popup-dialogs alert = driver.switch_to_alert() text = alert.text driver.reset() return text except (TimeoutException, URLError): driver.reset() return None
Example #5
Source File: jebi.py From jebi with MIT License | 6 votes |
def bt_bts_withdraw(amount): browser.get('http://btc38.com/trade_en.html') WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="header_login_text"]/a'))) login = browser.find_element_by_xpath('//*[@id="header_login_text"]/a') login.click() browser.get('http://www.btc38.com/trade/trade_setaddr_en.html?coinname=bts') WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="drawBalance"]'))) WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="memo"]'))) WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="submitDrawBTN"]/a'))) time.sleep(2) bts_amount = browser.find_element_by_xpath('//*[@id="drawBalance"]') # Make sure the Poloniex is on the top bts_amount.send_keys(str(amount)) bts_memo = browser.find_element_by_xpath('//*[@id="memo"]') bts_memo.send_keys(config_jebi.polo_bts_memo) bts_submit = browser.find_element_by_xpath('//*[@id="submitDrawBTN"]/a') bts_submit.click() WebDriverWait(browser, 10).until(EC.alert_is_present()) time.sleep(1) alert = browser.switch_to.alert time.sleep(1) alert.accept()
Example #6
Source File: jebi.py From jebi with MIT License | 6 votes |
def bt_btc_withdraw(amount): browser.get('http://btc38.com/trade_en.html') WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="header_login_text"]/a'))) login = browser.find_element_by_xpath('//*[@id="header_login_text"]/a') login.click() browser.get('http://www.btc38.com/trade/trade_setaddr_en.html?coinname=btc') WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="drawBalance"]'))) WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="submitDrawBTN"]/a'))) time.sleep(2) btc_amount = browser.find_element_by_xpath('//*[@id="drawBalance"]') # Make sure poloniex address is on the top btc_amount.send_keys(str(amount)) btc_submit = browser.find_element_by_xpath('//*[@id="submitDrawBTN"]/a') btc_submit.click() WebDriverWait(browser, 10).until(EC.alert_is_present()) time.sleep(1) alert = browser.switch_to.alert time.sleep(1) alert.accept()
Example #7
Source File: WebRunner.py From PyWebRunner with MIT License | 5 votes |
def wait_for_alert(self, **kwargs): ''' Shortcut for waiting for alert. If it not ends with exception, it returns that alert. ''' self._wait_for(EC.alert_is_present(), **kwargs)
Example #8
Source File: run_server_tests.py From anvio with GNU General Public License v3.0 | 5 votes |
def test11DeleteUser(self): self.loginAdmin() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'admin page'))) self.browser.find_element_by_link_text('admin page').click() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.XPATH, '//button[@onclick="showUserDetails(\'testuser2\');"]'))) self.browser.find_element_by_xpath('//button[@onclick="showUserDetails(\'testuser2\');"]').click() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.XPATH, '//button[@onclick="deleteUser(\'testuser2\')"]'))) self.browser.find_element_by_xpath('//button[@onclick="deleteUser(\'testuser2\')"]').click() WebDriverWait(self.browser, 5).until(EC.alert_is_present()) Alert(self.browser).send_keys('CONFIRM') Alert(self.browser).accept() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.ID, 'usertable'))) self.assertFalse(len(self.browser.find_elements_by_xpath('//button[@onclick="showUserDetails(\'testuser2\');"]')))
Example #9
Source File: run_server_tests.py From anvio with GNU General Public License v3.0 | 5 votes |
def test10DeleteProject(self): self.login() WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.ID, 'projectDelete0'))) self.browser.find_element_by_id('projectDelete0').click() WebDriverWait(self.browser, 5).until(EC.alert_is_present()) Alert(self.browser).accept() WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.XPATH, '//button[@title="upload data files"]'))) self.assertFalse(len(self.browser.find_elements_by_link_text('test_proj_01')))
Example #10
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 #11
Source File: driver.py From capybara.py with MIT License | 5 votes |
def _find_modal(self, text=None, wait=None): wait = wait or capybara.default_max_wait_time try: alert = WebDriverWait(self.browser, wait).until(EC.alert_is_present()) regexp = toregex(text) if not regexp.search(alert.text): qualifier = "matching" if isregex(text) else "with" raise ModalNotFound("Unable to find modal dialog {0} {1}".format(qualifier, desc(text))) return alert except TimeoutException: raise ModalNotFound("Unable to find modal dialog")
Example #12
Source File: driver.py From behave-webdriver with MIT License | 5 votes |
def has_alert(self): """ Whether or not there is currently an alert present :return: True if there is an alert present, else False :rtype: bool """ try: WebDriverWait(self, 1).until(EC.alert_is_present()) alert = self.switch_to.alert return True except TimeoutException: return False
Example #13
Source File: snapshot.py From sweetest with Mozilla Public License 2.0 | 5 votes |
def web_screen(self, step, element): # 截图 screen_v = self.output.get('#ScreenShot', '') element_v = self.output.get('#ElementShot', '') if g.snapshot or self.screen_flag or self.element_flag: from selenium.webdriver.support import expected_conditions as EC if not EC.alert_is_present()(g.driver): if self.expected.get('#ScreenName'): screen_name = self.expected['#ScreenName'] elif screen_v: screen_name = screen_v else: screen_name = '' if screen_name: file_name = self.label + now() + '#Screen' + '[' + screen_name + ']' + '.png' else: file_name = self.label + now() + '#Screen' + '.png' step['snapshot']['Real_Screen'] = str( Path(self.snapshot_folder) / file_name) get_screenshot(step['snapshot']['Real_Screen']) if screen_v: g.var[screen_v] = step['snapshot']['Real_Screen'] if element_v: file_name = self.label + now() + '#Element' + '[' + element_v + ']' + '.png' step['snapshot']['Real_Element'] = str(Path(self.snapshot_folder) / file_name) crop(element, step['snapshot']['Real_Screen'], step['snapshot']['Real_Element']) g.var[element_v] = step['snapshot']['Real_Element']
Example #14
Source File: extended_driver.py From golem with MIT License | 5 votes |
def alert_is_present(self): """Returns whether an alert is present""" try: self.switch_to.alert return True except NoAlertPresentException: return False
Example #15
Source File: extended_driver.py From golem with MIT License | 5 votes |
def wait_for_alert_present(self, timeout): """Wait for an alert to be present :Args: - timeout: time to wait (in seconds) """ wait = WebDriverWait(self, timeout) message = 'Timeout waiting for alert to be present' wait.until(ec.alert_is_present(), message=message)
Example #16
Source File: run_server_tests.py From anvio with GNU General Public License v3.0 | 5 votes |
def test03ForgotPasswordInvalid(self): self.browser.get('http://'+self.URL) self.browser.find_element_by_link_text('forgot password?').click() WebDriverWait(self.browser, 5).until(EC.title_is('anvio forgot password')) self.browser.find_element_by_id('inputEmail').send_keys('invalid@email.com') self.browser.find_element_by_id('submit').click() WebDriverWait(self.browser, 5).until(EC.alert_is_present()) self.assertEqual('Resetting password failed: No user has been found for email address "invalid@email.com"', Alert(self.browser).text)
Example #17
Source File: tests.py From django-userlog with BSD 3-Clause "New" or "Revised" License | 5 votes |
def accept_alert(self, expected_text, timeout=1): self.wait_until(ec.alert_is_present(), timeout) alert = self.selenium.switch_to_alert() self.assertEqual(alert.text, expected_text) alert.accept()
Example #18
Source File: foctor_core.py From centinel with MIT License | 4 votes |
def load_page(driver, url, cookies=0): try: if cookies == 0: driver.delete_all_cookies() time.sleep(1) if "http" not in url.split("/")[0]: url = "http://" + url switch_tab(driver) driver.get(url) logging.debug("driver.get(%s) returned successfully" % url) except (TimeoutException, TimeoutError) as te: logging.warning("Loading %s timed out" % url) return str(te) # try: # element = WebDriverWait(driver, .5).until(EC.alert_is_present()) # if element is not None: # print "Alert found on page: " + url # sys.stdout.flush() # raise TimeoutError # else: # raise NoAlertPresentException # except (TimeoutException, NoAlertPresentException): # print "No alert found on page: " + url # sys.stdout.flush() # pass # except TimeoutError as te: # sys.stdout.flush() # return str(te) # try: # main_handle = driver.current_window_handle # except CannotSendRequest as csr: # return str(csr) try: windows = driver.window_handles if len(windows) > 1: logging.debug("Pop up detected on page: %s. Closing driver instance." % url) raise TimeoutError # for window in windows: # if window != main_handle: # driver.switch_to_window(window) # driver.close() # driver.switch_to_window(main_handle) # wfrs_status = wait_for_ready_state(driver, 15, 'complete') # if wfrs_status == "Timed-out": # print "wait_for_ready_state() timed out." # raise TimeoutError except (TimeoutException, TimeoutError) as te: logging.warning("Loading %s timed out" % url) return str(te) return "No Error"