Python selenium.webdriver.common.keys.Keys.ESCAPE Examples
The following are 18
code examples of selenium.webdriver.common.keys.Keys.ESCAPE().
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.common.keys.Keys
, or try the search function
.
Example #1
Source File: legoshop.py From lego-mindstorms-ev3-comparison with GNU General Public License v3.0 | 7 votes |
def _process_survey(self): """ Validate Lego's survey form """ print("* Sometimes they ask you to fill in a survey.") try: # FIXME: survey's layer escape key no longer work survey_layer = self.browser.find_element_by_id('ipeL104230') survey_layer.send_keys(Keys.ESCAPE) # we should click on the "no" button to close the survey window # no_survey_button = self.browser.find_element_by_xpath( # "//area[contains(@onclick,'ipe.clWin')]") # no_survey_button.click() except NoSuchElementException: print("We're lucky, no survey on the LEGO shop today!")
Example #2
Source File: scraper.py From fb-ad-archive-scraper with MIT License | 6 votes |
def process_ad_divs(ad_divs, ad_count, driver, dirname, ad_limit, wait=0): # Add whitespace to bottom to allow scrolling to bottom row window_height = driver.execute_script('return window.innerHeight') driver.execute_script("arguments[0].setAttribute('style', 'margin-bottom:{}px;')".format(window_height), ad_divs[-1]) processed_add_divs = set() for ad_div in ad_divs: if ad_count > 0: sleep(wait) ad_count += 1 print('Ad {}'.format(ad_count)) screenshot(ad_div, ad_count, dirname, driver) # Click Ad Performance ad_div.find_element_by_partial_link_text('See Ad Performance').click() webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform() processed_add_divs.add(ad_div) if ad_limit == ad_count: break return processed_add_divs
Example #3
Source File: entity.py From selene with MIT License | 5 votes |
def press_escape(self) -> Element: return self.press(Keys.ESCAPE)
Example #4
Source File: test_utils.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _to_command_mode(self): """Changes us into command mode on currently focused cell """ self.body.send_keys(Keys.ESCAPE) self.browser.execute_script( "return Jupyter.notebook.handle_command_mode(" "Jupyter.notebook.get_cell(" "Jupyter.notebook.get_edit_index()))")
Example #5
Source File: test_project.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def test_create_project(self): self.selenium.get('{}{}'.format(self.live_server_url, reverse('project:create'))) create_form = self.selenium.find_element_by_id("id_create_form") name = 'TestProjekt' create_form.find_element_by_id("id_name").send_keys(name) create_form.find_element_by_id("id_name_short").send_keys('TP') create_form.find_element_by_id("id_description").send_keys('This is a description for our TestProject') create_form.find_element_by_css_selector('input.select2-search__field').send_keys('te') # TODO TESTCASE this doesn't work on the create form - y doesn't this work? self.selenium.find_element_by_css_selector( 'li.select2-results__option.select2-results__option--highlighted' ).click() create_form.find_element_by_css_selector("input.select2-search__field").send_keys(Keys.ESCAPE) create_form.find_element_by_id('id_submit_create').click() self.assertEqual(self.selenium.title, name)
Example #6
Source File: test_slack.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def test_issue_modify(self, slackmock): issue = Issue() issue.title = self.title_name issue.project = self.project issue.save() self.selenium.get( '{}{}'.format( self.live_server_url, reverse('issue:edit', kwargs={'project': self.short, 'sqn_i': issue.number}) ) ) # open assignee autocomplete field self.selenium.find_element_by_css_selector("input.select2-search__field").click() # select first result self.selenium.find_elements_by_css_selector('#select2-id_assignee-results li')[0].click() # close autocomplete self.selenium.find_element_by_css_selector("input.select2-search__field").send_keys(Keys.ESCAPE) self.selenium.find_element_by_id('id_submit_edit').click() slackmock.chat_postMessage.assert_called_with( channel="channel", attachments=[{ 'fallback': str(self.user) + " changed issue "+self.short+"-1 "+self.title_name+".", 'pretext': 'Issue changed:', 'title': self.short+"-1 "+self.title_name, 'title_link': "http://localhost:8000/project/"+self.short+"/issue/1/", 'author_name': str(self.user), 'author_link': "http://localhost:8000" + self.user.get_absolute_url(), 'author_icon': "http://localhost:8000" + self.user.avatar.url, 'fields': [{ 'title': 'Assignee', 'value': ' → a', 'short': True, }], 'color': 'good', }] )
Example #7
Source File: test_create_and_edit.py From iguana with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def test_create(self): driver = self.selenium driver.get("{}{}".format(self.live_server_url, reverse('issue:create', kwargs={'project': self.project.name_short}))) title = "title" driver.find_element_by_id("id_title").send_keys(title) # assert that initially selected kanbancol is 'Todo' self.assertEqual(Select(driver.find_element_by_id("id_kanbancol")).first_selected_option.text, "Todo") # assert that project has 4 (3 default + --- line) kanban colums self.assertEqual(len(Select(driver.find_element_by_id("id_kanbancol")).options), 4) Select(driver.find_element_by_id("id_kanbancol")).select_by_visible_text("Todo") driver.find_element_by_name("due_date").click() driver.find_element_by_name("due_date").send_keys(str(datetime.date.today().strftime("%m/%d/%Y"))) driver.find_element_by_name("due_date").send_keys(Keys.TAB) # close datepicker # assert that we have one assignee in selection field driver.find_element_by_css_selector("input.select2-search__field").click() self.assertEqual(len(driver.find_elements_by_css_selector('#select2-id_assignee-results li')), 1) driver.find_element_by_css_selector("input.select2-search__field").send_keys(Keys.ESCAPE) Select(driver.find_element_by_id("id_priority")).select_by_visible_text("High") driver.find_element_by_id("id_storypoints").clear() driver.find_element_by_id("id_storypoints").send_keys("2") # assert that project has no related issues to choose from (only one issue present in proj2) # one item present: No items found driver.find_element_by_xpath("(//input[@type='search'])[2]").send_keys(Keys.RETURN) time.sleep(1) self.assertEqual(len(driver.find_elements_by_css_selector('#select2-id_dependsOn-results li')), 1) for i in driver.find_elements_by_css_selector('#select2-id_dependsOn-results li'): self.assertEqual(i.text, "No results found") driver.find_element_by_id("wmd-input-id_description").clear() driver.find_element_by_id("wmd-input-id_description").send_keys("blubber") driver.find_element_by_id("id_submit_create").click() self.assertIn(title, driver.page_source)
Example #8
Source File: api.py From redtide with MIT License | 5 votes |
def _change_order_type(self, order_type='market'): if order_type not in ['market', 'limit', 'stopLoss', 'stopLimit', 'trailingStop']: raise ValueError('Invalid order type, order_type={}'.format(order_type)) def _select(v): self.driver.find_element_by_xpath( '//span[contains(., "{} Order")]/parent::span' '/parent::div/parent::div'.format(v)).click() # click the drop-down self.driver.find_elements_by_xpath( '//form[@data-testid="OrderForm"]/div[1]/div[1]/div')[-1].click() if order_type == 'market': _select('Market') elif order_type == 'limit': _select('Limit') elif order_type == 'stopLoss': _select('Stop Loss') elif order_type == 'stopLimit': _select('Stop Limit') elif order_type == 'trailingStop': _select('Trailing Stop') else: self.driver.find_element_by_tag_name('body').send_keys(Keys.ESCAPE) raise ValueError('No such order type: {}'.format(order_type))
Example #9
Source File: formgrade_utils.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _save_score(browser, index): _send_keys_to_body(browser, Keys.ESCAPE) glyph = browser.find_elements_by_css_selector(".score-saved")[index] WebDriverWait(browser, 10).until(lambda browser: glyph.is_displayed()) WebDriverWait(browser, 10).until(lambda browser: not glyph.is_displayed())
Example #10
Source File: formgrade_utils.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _save_comment(browser, index): _send_keys_to_body(browser, Keys.ESCAPE) glyph = browser.find_elements_by_css_selector(".comment-saved")[index] WebDriverWait(browser, 10).until(lambda browser: glyph.is_displayed()) WebDriverWait(browser, 10).until(lambda browser: not glyph.is_displayed())
Example #11
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_task_cell_ids(browser, port): _load_notebook(browser, port, name='task') _activate_toolbar(browser) # turn it into a cell with an id _select_task(browser) _set_id(browser, cell_id="") # save and check for an error (blank id) _save(browser) _wait_for_modal(browser) _dismiss_modal(browser) # set the label _set_id(browser) # create a new cell element = browser.find_element_by_tag_name("body") element.send_keys(Keys.ESCAPE) element.send_keys("b") # make sure the toolbar appeared def find_toolbar(browser): try: browser.find_elements_by_css_selector(".celltoolbar select")[1] except IndexError: return False return True _wait(browser).until(find_toolbar) # make it a test cell and set the label _select_task(browser, index=1) _set_id(browser, index=1) # save and check for an error (duplicate id) _save(browser) _wait_for_modal(browser) _dismiss_modal(browser)
Example #12
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_cell_ids(browser, port): _load_notebook(browser, port) _activate_toolbar(browser) # turn it into a cell with an id _select_solution(browser) # for some reason only one call doesn't trigger on_change event _select_solution(browser) _set_id(browser, cell_id="") # save and check for an error (blank id) _save(browser) _wait_for_modal(browser) _dismiss_modal(browser) # set the label _set_id(browser) # create a new cell element = browser.find_element_by_tag_name("body") element.send_keys(Keys.ESCAPE) element.send_keys("b") # make sure the toolbar appeared def find_toolbar(browser): try: browser.find_elements_by_css_selector(".celltoolbar select")[1] except IndexError: return False return True _wait(browser).until(find_toolbar) # make it a test cell and set the label _select_tests(browser, index=1) _set_id(browser, index=1) # save and check for an error (duplicate id) _save(browser) _wait_for_modal(browser) _dismiss_modal(browser)
Example #13
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 4 votes |
def test_show_hide_date_time_picker_widgets(self): """ Pressing the ESC key or clicking on a widget value closes the date and time picker widgets. """ from selenium.webdriver.common.keys import Keys self.admin_login(username='super', password='secret', login_url='/') # Open a page that has a date and time picker widgets self.selenium.get(self.live_server_url + reverse('admin:admin_widgets_member_add')) # First, with the date picker widget --------------------------------- cal_icon = self.selenium.find_element_by_id('calendarlink0') # The date picker is hidden self.assertEqual(self.get_css_value('#calendarbox0', 'display'), 'none') # Click the calendar icon cal_icon.click() # The date picker is visible self.assertEqual(self.get_css_value('#calendarbox0', 'display'), 'block') # Press the ESC key self.selenium.find_element_by_tag_name('body').send_keys([Keys.ESCAPE]) # The date picker is hidden again self.assertEqual(self.get_css_value('#calendarbox0', 'display'), 'none') # Click the calendar icon, then on the 15th of current month cal_icon.click() self.selenium.find_element_by_xpath("//a[contains(text(), '15')]").click() self.assertEqual(self.get_css_value('#calendarbox0', 'display'), 'none') self.assertEqual( self.selenium.find_element_by_id('id_birthdate_0').get_attribute('value'), datetime.today().strftime('%Y-%m-') + '15', ) # Then, with the time picker widget ---------------------------------- time_icon = self.selenium.find_element_by_id('clocklink0') # The time picker is hidden self.assertEqual(self.get_css_value('#clockbox0', 'display'), 'none') # Click the time icon time_icon.click() # The time picker is visible self.assertEqual(self.get_css_value('#clockbox0', 'display'), 'block') self.assertEqual( [ x.text for x in self.selenium.find_elements_by_xpath("//ul[@class='timelist']/li/a") ], ['Now', 'Midnight', '6 a.m.', 'Noon', '6 p.m.'] ) # Press the ESC key self.selenium.find_element_by_tag_name('body').send_keys([Keys.ESCAPE]) # The time picker is hidden again self.assertEqual(self.get_css_value('#clockbox0', 'display'), 'none') # Click the time icon, then select the 'Noon' value time_icon.click() self.selenium.find_element_by_xpath("//a[contains(text(), 'Noon')]").click() self.assertEqual(self.get_css_value('#clockbox0', 'display'), 'none') self.assertEqual( self.selenium.find_element_by_id('id_birthdate_1').get_attribute('value'), '12:00:00', )
Example #14
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_total_points(browser, port): _load_notebook(browser, port, 'task') _activate_toolbar(browser) # make sure the total points is zero assert _get_total_points(browser) == 0 # make it autograder tests and set the points to two _select_task(browser) _set_points(browser) _set_id(browser) assert _get_total_points(browser) == 2 # make it manually graded _select_manual(browser) assert _get_total_points(browser) == 2 # make it a solution make sure the total points is zero _select_solution(browser) assert _get_total_points(browser) == 0 # make it task _select_task(browser) assert _get_total_points(browser) == 0 _set_points(browser) assert _get_total_points(browser) == 2 # create a new cell element = browser.find_element_by_tag_name("body") element.send_keys(Keys.ESCAPE) element.send_keys("b") # make sure the toolbar appeared def find_toolbar(browser): try: browser.find_elements_by_css_selector(".celltoolbar select")[1] except IndexError: return False return True _wait(browser).until(find_toolbar) # make it a test cell _select_tests(browser, index=1) _set_points(browser, points=1, index=1) _set_id(browser, cell_id="bar", index=1) assert _get_total_points(browser) == 3 # delete the new cell element = browser.find_elements_by_css_selector(".cell")[0] element.click() element.send_keys(Keys.ESCAPE) element.send_keys("d") element.send_keys("d") assert _get_total_points(browser) == 1 # delete the first cell element = browser.find_elements_by_css_selector(".cell")[0] element.send_keys("d") element.send_keys("d") assert _get_total_points(browser) == 0
Example #15
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 4 votes |
def test_total_points(browser, port): _load_notebook(browser, port) _activate_toolbar(browser) # make sure the total points is zero assert _get_total_points(browser) == 0 # make it autograder tests and set the points to two _select_tests(browser) _set_points(browser) _set_id(browser) assert _get_total_points(browser) == 2 # make it manually graded _select_manual(browser) assert _get_total_points(browser) == 2 # make it a solution make sure the total points is zero _select_solution(browser) assert _get_total_points(browser) == 0 # make it autograder tests _select_tests(browser) assert _get_total_points(browser) == 0 _set_points(browser) assert _get_total_points(browser) == 2 # create a new cell element = browser.find_element_by_tag_name("body") element.send_keys(Keys.ESCAPE) element.send_keys("b") # make sure the toolbar appeared def find_toolbar(browser): try: browser.find_elements_by_css_selector(".celltoolbar select")[1] except IndexError: return False return True _wait(browser).until(find_toolbar) # make it a test cell _select_tests(browser, index=1) _set_points(browser, points=1, index=1) _set_id(browser, cell_id="bar", index=1) assert _get_total_points(browser) == 3 # delete the new cell element = browser.find_elements_by_css_selector(".cell")[0] element.click() element.send_keys(Keys.ESCAPE) element.send_keys("d") element.send_keys("d") assert _get_total_points(browser) == 1 # delete the first cell element = browser.find_elements_by_css_selector(".cell")[0] element.send_keys("d") element.send_keys("d") assert _get_total_points(browser) == 0
Example #16
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _load_notebook(browser, port, retries=5, name="blank"): # go to the correct page url = "http://localhost:{}/notebooks/{}.ipynb".format(port, name) browser.get(url) alert = '' for _ in range(5): if alert is None: break try: alert = browser.switch_to.alert except NoAlertPresentException: alert = None else: print("Warning: dismissing unexpected alert ({})".format(alert.text)) alert.accept() def page_loaded(browser): return browser.execute_script( """ return (typeof Jupyter !== "undefined" && Jupyter.page !== undefined && Jupyter.notebook !== undefined && $("#notebook_name").text() === "{}" && Jupyter.notebook._fully_loaded); """.format(name)) # wait for the page to load try: _wait(browser).until(page_loaded) except TimeoutException: if retries > 0: print("Retrying page load...") # page timeout, but sometimes this happens, so try refreshing? _load_notebook(browser, port, retries=retries - 1, name=name) else: print("Failed to load the page too many times") raise # Hack: there seems to be some race condition here where sometimes the # page is still not fully loaded, but I can't figure out exactly what I need # to check for to ensure that it is. So for now just add a small sleep to # make sure everything finishes loading, though this is not really a robust # fix for the problem :/ time.sleep(1) # delete all cells if name == "blank": cells = browser.find_elements_by_css_selector(".cell") for _ in range(len(cells)): element = browser.find_elements_by_css_selector(".cell")[0] element.click() element.send_keys(Keys.ESCAPE) element.send_keys("d") element.send_keys("d")
Example #17
Source File: test_sequence_viewer.py From dash-bio with MIT License | 4 votes |
def test_dbsv005_mouse_selection(dash_duo): app = dash.Dash(__name__) app.layout = html.Div(user_interactions_layout( dash_bio.SequenceViewer( id=_COMPONENT_ID, sequence=_data ) )) user_interactions_callback( app, dash_duo, component_id=_COMPONENT_ID, prop_name='mouseSelection' ) output_div = dash_duo.find_element('#interaction-results') sequence = dash_duo.find_element('.fastaSeq') ac = ActionChains(dash_duo.driver) ac.move_to_element(sequence) ac.move_by_offset( -(sequence.size['width']/2), -(sequence.size['height']/2) ) ac.click_and_hold() ac.move_by_offset(85, 0) ac.release() ac.perform() expected_info = { 'selection': 'MALWMRLLPL', 'start': 1, 'end': 10 } assert output_div.get_attribute('innerHTML') == json.dumps(expected_info) # select something else ac = ActionChains(dash_duo.driver) ac.move_to_element(sequence) ac.move_by_offset( -(sequence.size['width']/2 - 100), -(sequence.size['height']/2 - 20) ) ac.click_and_hold() ac.move_by_offset(55, 0) ac.release() ac.perform() expected_info = { 'selection': 'PKTRREA', 'start': 52, 'end': 58 } assert output_div.get_attribute('innerHTML') == json.dumps(expected_info) ac.send_keys(Keys.ESCAPE)
Example #18
Source File: kleinanzeigen.py From ebayKleinanzeigen with Apache License 2.0 | 4 votes |
def delete_ad(driver, ad): log.info("\tDeleting ad ...") driver.get("https://www.ebay-kleinanzeigen.de/m-meine-anzeigen.html") fake_wait() ad_id_elem = None if "id" in ad: try: ad_id_elem = driver.find_element_by_xpath("//a[@data-adid='%s']" % ad["id"]) except NoSuchElementException as e: log.info("\tNot found by ID") if ad_id_elem is None: try: ad_id_elem = driver.find_element_by_xpath("//a[contains(text(), '%s')]/../../../../.." % ad["title"]) except NoSuchElementException as e: log.info("\tNot found by title") if ad_id_elem is not None: try: btn_del = ad_id_elem.find_element_by_class_name("managead-listitem-action-delete") btn_del.click() fake_wait() btn_confirm_del = driver.find_element_by_id("modal-bulk-delete-ad-sbmt") btn_confirm_del.click() log.info("\tAd deleted") fake_wait(randint(2000, 3000)) webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform() return True except NoSuchElementException as e: log.info("\tDelete button not found") else: log.info("\tAd does not exist (anymore)") ad.pop("id", None) return False # From: https://stackoverflow.com/questions/983354/how-do-i-make-python-to-wait-for-a-pressed-key