本文整理匯總了Python中selenium.webdriver.common.keys.Keys.TAB屬性的典型用法代碼示例。如果您正苦於以下問題:Python Keys.TAB屬性的具體用法?Python Keys.TAB怎麽用?Python Keys.TAB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類selenium.webdriver.common.keys.Keys
的用法示例。
在下文中一共展示了Keys.TAB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lambda_handler
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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()
示例2: proxy_authentication
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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")
示例3: switch_tab
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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")
示例4: load
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)
示例5: tab
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
def tab(self):
elem = self.__get_element(self.k, self.v)
elem.send_keys(Keys.TAB)
示例6: set_timeframe
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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
示例7: tab
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
def tab(self):
self.elem.send_keys(Keys.TAB)
示例8: focus_on_caption_line
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)
示例9: set_element_value
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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
示例10: set_field_value
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)
示例11: _test_skip_link
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)
示例12: test_create
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)
示例13: test_tabbing
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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"))
示例14: press_tab
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
def press_tab(self) -> Element:
return self.press(Keys.TAB)
示例15: set_expiration
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import TAB [as 別名]
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)