Python selenium.webdriver.common.keys.Keys.TAB Examples
The following are 19
code examples of selenium.webdriver.common.keys.Keys.TAB().
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: foctor_core.py From centinel with MIT License | 7 votes |
def switch_tab(driver): main_window = driver.current_window_handle body = driver.find_element_by_tag_name("body") # body.send_keys(Keys.CONTROL + 't') body.send_keys(Keys.CONTROL + 't') driver.switch_to_window(main_window) body_tab = driver.find_element_by_tag_name("body") time.sleep(.5) if body == body_tab: logging.warning("Switch tab failed") else: body_tab.send_keys(Keys.CONTROL + Keys.TAB) driver.switch_to_window(main_window) body = driver.find_element_by_tag_name("body") body.send_keys(Keys.CONTROL + 'w') driver.switch_to_window(main_window) body_tab = driver.find_element_by_tag_name("body") body_tab.send_keys(Keys.CONTROL + Keys.TAB) driver.switch_to_window(main_window) body = driver.find_element_by_tag_name("body") if body != body_tab: logging.warning("Failed to switch tab, switch back to previous tab")
Example #2
Source File: lambda_function.py From pychromeless with Apache License 2.0 | 6 votes |
def lambda_handler(*args, **kwargs): driver = WebDriverWrapper() driver.get_url('https://www.google.es/') driver.set_input_value('//input[@name="q"]', '21 buttons') button = driver.find("//input[@name='btnK']") button.send_keys(Keys.TAB) driver.click('//input[@name="btnK"]') first_google_result_title = driver.get_inner_html('(//div[@class="rc"]//a)[1]') print("--------------------------") print(first_google_result_title) print("--------------------------") driver.close()
Example #3
Source File: browser.py From bot with GNU General Public License v3.0 | 6 votes |
def proxy_authentication(browser, logger, proxy_username, proxy_password): """ Authenticate proxy using popup alert window """ # FIXME: https://github.com/SeleniumHQ/selenium/issues/7239 # this feauture is not working anymore due to the Selenium bug report above logger.warn( "Proxy Authentication is not working anymore due to the Selenium bug " "report: https://github.com/SeleniumHQ/selenium/issues/7239" ) try: # sleep(1) is enough, sleep(2) is to make sure we # give time to the popup windows sleep(2) alert_popup = browser.switch_to_alert() alert_popup.send_keys( "{username}{tab}{password}{tab}".format( username=proxy_username, tab=Keys.TAB, password=proxy_password ) ) alert_popup.accept() except Exception: logger.warn("Unable to proxy authenticate")
Example #4
Source File: entity.py From selene with MIT License | 5 votes |
def press_tab(self) -> Element: return self.press(Keys.TAB)
Example #5
Source File: from_xueqiu.py From Financial-NLP with Apache License 2.0 | 5 votes |
def load(x,article_number): flag=1 # 表示尚未拉到底部 L=0 while(flag or L<article_number): L=len(x.find_elements_by_class_name('home__timeline__item')) try: x.find_element_by_class_name('home__timeline__more').click() flag=0 except: x.find_elements_by_class_name('home__timeline__item')[-1].find_element_by_xpath('h3/a').send_keys(Keys.TAB) print('loaded %d articles.' % L)
Example #6
Source File: test_create_assignment.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_tabbing(browser, port): _load_notebook(browser, port) _activate_toolbar(browser) def active_element_is(class_name): def waitfor(browser): elem = browser.execute_script("return document.activeElement") return elem.get_attribute("class") == class_name return waitfor # make it manually graded _select_manual(browser) # click the id field element = browser.find_element_by_css_selector(".nbgrader-points-input") # There is a bug where sometimes the click doesn't register, so we also press enter # here which for some reason seems to help. It's not clear here what's happening # to cause this bug but see https://github.com/mozilla/geckodriver/issues/322 for # reference. It only seemed to be a problem on Linux, not Mac or Windows. element.click() element.send_keys(Keys.RETURN) _wait(browser).until(active_element_is("nbgrader-points-input")) # press tab and check that the active element is correct element.send_keys(Keys.TAB) _wait(browser).until(active_element_is("nbgrader-id-input")) # make it autograder tests _select_tests(browser) # click the id field element = browser.find_element_by_css_selector(".nbgrader-points-input") element.click() element.send_keys(Keys.RETURN) _wait(browser).until(active_element_is("nbgrader-points-input")) # press tab and check that the active element is correct element.send_keys(Keys.TAB) _wait(browser).until(active_element_is("nbgrader-id-input"))
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: mixins.py From edx-analytics-dashboard with GNU Affero General Public License v3.0 | 5 votes |
def _test_skip_link(self, test_url): active_element = self.driver.switch_to.active_element skip_link = self.page.q(css='.skip-link').results[0] skip_link_ref = '#' + skip_link.get_attribute('href').split('#')[-1] target_element = self.page.q(css=skip_link_ref) self.assertEqual(len(target_element), 1) active_element.send_keys(Keys.TAB) active_element = self.driver.switch_to.active_element active_element.send_keys(Keys.ENTER) if test_url: url_hash = self.driver.execute_script('return window.location.hash;') self.assertEqual(url_hash, skip_link_ref)
Example #9
Source File: component_settings_editor_helpers.py From ANALYSE with GNU Affero General Public License v3.0 | 5 votes |
def set_field_value(index, value): """ Set the field to the specified value. Note: we cannot use css_fill here because the value is not set until after you move away from that field. Instead we will find the element, set its value, then hit the Tab key to get to the next field. """ elem = world.css_find('.metadata_edit div.wrapper-comp-setting input.setting-input')[index] elem.value = value elem.type(Keys.TAB)
Example #10
Source File: common.py From ANALYSE with GNU Affero General Public License v3.0 | 5 votes |
def set_element_value(element_css, element_value, key=None): element = world.css_find(element_css).first element.fill(element_value) # hit TAB or provided key to trigger save content if key is not None: element._element.send_keys(getattr(Keys, key)) # pylint: disable=protected-access else: element._element.send_keys(Keys.TAB) # pylint: disable=protected-access
Example #11
Source File: video.py From ANALYSE with GNU Affero General Public License v3.0 | 5 votes |
def focus_on_caption_line(_step, index): world.wait_for_present('.video.is-captions-rendered') world.wait_for(lambda _: world.css_text('.subtitles'), timeout=30) find_caption_line_by_data_index(int(index.strip()))._element.send_keys(Keys.TAB)
Example #12
Source File: webdriver.py From seldom with Apache License 2.0 | 5 votes |
def tab(self): self.elem.send_keys(Keys.TAB)
Example #13
Source File: tv.py From Kairos with GNU General Public License v3.0 | 5 votes |
def set_timeframe(browser, timeframe): log.info('Setting timeframe to ' + timeframe) wait_and_click(browser, css_selectors['btn_timeframe']) css = css_selectors['options_timeframe'] el_options = find_elements(browser, css) index = 0 found = False while not found and index < len(el_options): if el_options[index].text == timeframe: el_options[index].click() found = True index += 1 if not found: log.warning('Unable to set timeframe to ' + timeframe) raise ValueError if found: # TODO replace 'element.send_keys" with # action = ActionChains(browser) # action.send_keys(Keys.TAB) # action.perform() html = find_element(browser, 'html', By.TAG_NAME) html.send_keys(MODIFIER_KEY + 's') time.sleep(DELAY_BREAK) return found
Example #14
Source File: page_objects.py From poium with Apache License 2.0 | 5 votes |
def tab(self): elem = self.__get_element(self.k, self.v) elem.send_keys(Keys.TAB)
Example #15
Source File: browser_mgmt.py From warriorframework with Apache License 2.0 | 4 votes |
def switch_tab(self, browser_instance=None, tab_number=None, browser_type="firefox"): """Switching to different tabs in a browser with unique tab_number""" status = True if browser_instance is None: browser_instance = self.current_browser if tab_number is not None: try: tab_number = int(tab_number) except: print_error("{0} is not a valid tab number".format(tab_number)) status = False else: if tab_number > len(browser_instance.window_handles) or tab_number < 1: print_error("{0} is not a valid tab number".format(tab_number)) status = False else: tab_number -= 1 current_tab = 0 current_window_handle = browser_instance.current_window_handle for i in range(0, len(browser_instance.window_handles)): if browser_instance.window_handles[i] == current_window_handle: current_tab = i break if tab_number != current_tab: if current_tab < tab_number: times = tab_number - current_tab else: times = len(browser_instance.window_handles) - current_tab times += tab_number if browser_type == "firefox": action_chains = ActionChains(browser_instance) action_chains.key_down(Keys.ALT) for i in range(0, times): action_chains.send_keys('`') action_chains.perform() else: element = browser_instance.find_element_by_tag_name('body') for i in range(0, times): element.send_keys(Keys.LEFT_CONTROL, Keys.TAB) browser_instance.switch_to.window(browser_instance.window_handles[tab_number]) else: current_tab = 0 current_window_handle = browser_instance.current_window_handle for i in range(0, len(browser_instance.window_handles)): if browser_instance.window_handles[i] == current_window_handle: current_tab = i tab_number = current_tab + 1 if tab_number >= len(browser_instance.window_handles): tab_number = 0 if browser_type == "firefox": browser_instance.find_element_by_tag_name('body').send_keys(Keys.LEFT_ALT, '`') else: browser_instance.find_element_by_tag_name('body').send_keys(Keys.LEFT_CONTROL, Keys.TAB) browser_instance.switch_to.window(browser_instance.window_handles[tab_number]) return status
Example #16
Source File: browser_mgmt.py From warriorframework with Apache License 2.0 | 4 votes |
def close_tab(self, browser_instance=None, tab_number=None, browser_type="firefox"): """Closing tabs in a browser with unique tab_number""" if browser_instance is None: browser_instance = self.current_browser if len(browser_instance.window_handles) > 1: prior_current_tab = False current_window_handler = browser_instance.current_window_handle for i in range(0, len(browser_instance.window_handles)): if browser_instance.window_handles[i] == current_window_handler: prior_current_tab = i status = True if tab_number is not None: status = self.switch_tab(browser_instance, tab_number, browser_type) if status: tab_number = int(tab_number) - 1 browser_instance.find_element_by_tag_name('body').send_keys(Keys.LEFT_CONTROL, 'w') sleep(2) if tab_number == len(browser_instance.window_handles): tab_number -= 1 browser_instance.switch_to.window(browser_instance.window_handles[tab_number]) if prior_current_tab == len(browser_instance.window_handles): prior_current_tab -= 1 if prior_current_tab != tab_number: if tab_number < prior_current_tab: times = prior_current_tab - tab_number else: times = len(browser_instance.window_handles) - tab_number times += prior_current_tab if browser_type == "firefox": action_chains = ActionChains(browser_instance) action_chains.key_down(Keys.ALT) for i in range(0, times): action_chains.send_keys('`') action_chains.perform() else: element = browser_instance.find_element_by_tag_name('body') for i in range(0, times): element.send_keys(Keys.LEFT_CONTROL, Keys.TAB) browser_instance.switch_to.window(browser_instance.window_handles[prior_current_tab]) else: if browser_type == "firefox": print_info("The tab_number argument is None. Current window will be closed") else: print_info("The tab_number argument is None. Current tab will be closed") browser_instance.find_element_by_tag_name('body').send_keys(Keys.LEFT_CONTROL, 'w') if prior_current_tab == len(browser_instance.window_handles): prior_current_tab = 0 browser_instance.switch_to.window(browser_instance.window_handles[prior_current_tab]) else: status = self.close_browser(browser_instance) return status
Example #17
Source File: WebRunner.py From PyWebRunner with MIT License | 4 votes |
def set_selectize(self, selector, value, text=None, clear=True, blur=False): ''' Sets visible value of a selectize control based on the "selectized" element. Parameters ---------- selector: str A CSS selector to search for. This can be any valid CSS selector. value: str The value of the option to select. (Stored Value) text: str The visible value that the user sees. (Visible value, if different than the stored value) clear: bool Whether or not we should clear the selectize value first. Defaults to True blur: bool Whether or not we should blur the element after setting the value. This corresponds to the 'selectOnTab' selecize setting. Defaults to False ''' selectize_control = selector + ' + .selectize-control' selectize_input = selectize_control + ' input' # Make sure the selectize control is active so the input is visible self.click(selectize_control) input_element = self.get_element(selectize_input) if clear: input_element.send_keys(Keys.BACK_SPACE) input_element.send_keys(text or value) # Wait for options to be rendered self.wait_for_visible(selectize_control + ' .has-options') if blur: input_element.send_keys(Keys.TAB) else: # Click the option for the given value self.click(selectize_control + ' .option[data-value="{}"]'.format(value))
Example #18
Source File: WebRunner.py From PyWebRunner with MIT License | 4 votes |
def set_value(self, selector, value, clear=True, blur=True, **kwargs): ''' Sets value of an element by CSS selector. Parameters ---------- selector: str A CSS selector to search for. This can be any valid CSS selector. value: str The value to set on the element matched by the selector. clear: bool Whether or not we should clear the element's value first. If false, value will be appended to the current value of the element. blur: bool Whether or not we should blur the element after setting the value. Defaults to True kwargs: passed on to wait_for_visible ''' typing = kwargs.get('typing', False) typing_speed = kwargs.get('typing_speed', 3) typing_max_delay = kwargs.get('typing_max_delay', .33) self.wait_for_visible(selector, **kwargs) elem = kwargs.get('elem') if not elem: elem = self.get_element(selector) if elem.tag_name == 'select': self.set_select_by_value(elem, value) else: if clear: self.clear(selector) if typing: for k in value: delay = random() / typing_speed if delay > typing_max_delay: delay = typing_max_delay sleep(delay) elem.send_keys(k) else: elem.send_keys(value) if self.driver == 'Gecko': # Thank you so much Mozilla. This is awesome to have to do. self.js("arguments[0].setAttribute('value', '" + value + "')", elem) if blur: elem.send_keys(Keys.TAB)
Example #19
Source File: tv.py From Kairos with GNU General Public License v3.0 | 4 votes |
def set_expiration(browser, _alert_dialog, alert_config): max_minutes = 86400 datetime_format = '%Y-%m-%d %H:%M' exp = alert_config['expiration'] if type(exp) is int: alert_config['expiration'] = dict() alert_config['expiration']['time'] = exp alert_config['expiration']['open-ended'] = False else: if 'time' not in alert_config['expiration']: alert_config['expiration']['time'] = exp if 'open-ended' not in alert_config['expiration']: alert_config['expiration']['open-ended'] = False checkbox = find_element(_alert_dialog, css_selectors['checkbox_dlg_create_alert_open_ended']) if is_checkbox_checked(checkbox) != alert_config['expiration']['open-ended']: wait_and_click(_alert_dialog, css_selectors['clickable_dlg_create_alert_open_ended']) if alert_config['expiration']['open-ended'] or str(alert_config['expiration']['time']).strip() == '' or str(alert_config['expiration']['time']).strip().lower().startswith('n') or type(alert_config['expiration']['time']) is None: return elif type(alert_config['expiration']['time']) is int: target_date = datetime.datetime.now() + datetime.timedelta(minutes=float(alert_config['expiration']['time'])) elif type(alert_config['expiration']['time']) is str and len(str(alert_config['expiration']['time']).strip()) > 0: target_date = datetime.datetime.strptime(str(alert_config['expiration']['time']).strip(), datetime_format) else: return max_expiration = datetime.datetime.now() + datetime.timedelta(minutes=float(max_minutes - 1440)) if target_date > max_expiration: target_date = max_expiration date_value = target_date.strftime('%Y-%m-%d') time_value = target_date.strftime('%H:%M') # For some reason TV does not register setting the date value directly. # Furthermore, we need to make sure that the date and time inputs are cleared beforehand. input_date = find_element(alert_dialog, 'alert_exp_date', By.NAME) clear(input_date) set_value(browser, input_date, date_value, False, True) input_time = find_element(_alert_dialog, 'alert_exp_time', By.NAME) time.sleep(DELAY_BREAK_MINI) clear(input_time) set_value(browser, input_time, time_value, False, True) send_keys(input_time, Keys.TAB) time.sleep(DELAY_BREAK_MINI)