本文整理匯總了Python中selenium.webdriver.common.keys.Keys.ENTER屬性的典型用法代碼示例。如果您正苦於以下問題:Python Keys.ENTER屬性的具體用法?Python Keys.ENTER怎麽用?Python Keys.ENTER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類selenium.webdriver.common.keys.Keys
的用法示例。
在下文中一共展示了Keys.ENTER屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_class
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def setup_class(self):
"""
Setup: Open a mozilla browser, login
"""
self.browser = Firefox()
self.browser.get('http://localhost:5000/')
token = self.browser.find_element_by_name("token")
password = "foo"
# login
token.send_keys(password)
token.send_keys(Keys.ENTER)
time.sleep(.1)
try:
self.browser.find_element_by_xpath("//input[@value='Logout']")
except NoSuchElementException:
raise ValueError("Can't login!!! Create a user 'foo' with the permissions"
"'read' and 'create' in your PERMISSIONS in the config")
示例2: send_message
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
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
示例3: get_last_seen
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
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
示例4: clear_chat
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def clear_chat(self, name):
self.browser.find_element_by_css_selector("._3FRCZ").send_keys(name+Keys.ENTER)
menu_xpath = "/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/div/span"
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, menu_xpath)))
menu = self.browser.find_element_by_xpath(menu_xpath)
menu.click()
chains = ActionChains(self.browser)
for i in range(4):
chains.send_keys(Keys.ARROW_DOWN)
chains.send_keys(Keys.ENTER)
chains.perform()
clear_xpath = '//*[@id="app"]/div/span[2]/div/div/div/div/div/div/div[2]/div[2]'
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, clear_xpath)))
self.browser.find_element_by_xpath(clear_xpath).click()
# override the timeout
示例5: get_profile_pic
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def get_profile_pic(self, name):
search = self.browser.find_element_by_css_selector("._3FRCZ")
search.send_keys(name+Keys.ENTER)
try:
open_profile = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div[1]/div/div/div[3]/div/header/div[1]/div/img")))
open_profile.click()
except:
print("nothing found")
try:
open_pic = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div[1]/div/div/div[1]/div[3]/span/div/span/div/div/div/div[1]/div[1]/div/img")))
open_pic.click()
except:
print("Nothing found")
try:
img = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
(By.XPATH,'//*[@id="app"]/div/span[2]/div/div/div[2]/div/div/div/div/img')))
except:
print("Couldn't find the URL to the image")
img_src_url = img.get_attribute('src')
self.browser.get(img_src_url)
self.browser.save_screenshot(name+"_img.png")
示例6: get_invite_link_for_group
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def get_invite_link_for_group(self, groupname):
search = self.browser.find_element_by_css_selector("._3FRCZ")
search.send_keys(groupname+Keys.ENTER)
self.browser.find_element_by_css_selector("#main > header > div._5SiUq > div._16vzP > div > span").click()
try:
#time.sleep(3)
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.CSS_SELECTOR, "#app > div > div > div.MZIyP > div._3q4NP._2yeJ5 > span > div > span > div > div > div > div:nth-child(5) > div:nth-child(3) > div._3j7s9 > div > div")))
invite_link = self.browser.find_element_by_css_selector("#app > div > div > div.MZIyP > div._3q4NP._2yeJ5 > span > div > span > div > div > div > div:nth-child(5) > div:nth-child(3) > div._3j7s9 > div > div")
invite_link.click()
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.ID, "group-invite-link-anchor")))
link = self.browser.find_element_by_id("group-invite-link-anchor")
return link.text
except:
print("Cannot get the link")
# This method is used to exit a group
示例7: send_anon_message
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def send_anon_message(self, phone, text):
payload = urlencode({"phone": phone, "text": text, "source": "", "data": ""})
self.browser.get("https://api.whatsapp.com/send?"+payload)
try:
Alert(self.browser).accept()
except:
print("No alert Found")
WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#action-button")))
send_message = self.browser.find_element_by_css_selector("#action-button")
send_message.click()
confirm = WebDriverWait(self.browser, self.timeout+5).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
confirm.clear()
confirm.send_keys(text+Keys.ENTER)
# Check if the message is present in an user chat
示例8: test_todo_mvc
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def test_todo_mvc(selenium):
with selenium.example():
time.sleep(0.5)
title_input = selenium.element_present("title-input")
title_input.clear()
title_input.send_keys("new todo")
title_input.send_keys(Keys.ENTER)
title_input.send_keys("completed")
title_input.send_keys(Keys.ENTER)
toggle_buttons = selenium.driver.find_elements_by_class_name("toggle")
assert 2 == len(toggle_buttons)
toggle_buttons[1].click()
selenium.element_present("show-active").click()
labels = selenium.driver.find_elements_by_tag_name("label")
assert 1 == len(labels)
assert "new todo" == labels[0].text
selenium.element_present("show-all").click()
labels = selenium.driver.find_elements_by_tag_name("label")
assert 2 == len(labels)
assert "new todo" == labels[0].text
assert "completed" == labels[1].text
示例9: retry_process_symbol
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def retry_process_symbol(browser, chart, symbol, timeframe, counter_alerts, total_alerts, retry_number=0):
if retry_number < config.getint('tradingview', 'create_alert_max_retries'):
log.info('trying again ({})'.format(str(retry_number + 1)))
refresh(browser)
try:
# might be useful for multi threading set the symbol by going to different url like this:
# https://www.tradingview.com/chart/?symbol=BINANCE%3AAGIBTC
input_symbol = find_element(browser, css_selectors['input_symbol'])
set_value(browser, input_symbol, symbol)
input_symbol.send_keys(Keys.ENTER)
# time.sleep(DELAY_CHANGE_SYMBOL)
except Exception as err:
log.debug('Unable to change to symbol')
log.exception(err)
snapshot(browser)
return process_symbol(browser, chart, symbol, timeframe, counter_alerts, total_alerts, False, retry_number + 1)
else:
log.error('Max retries reached.')
if symbol not in processing_errors:
processing_errors.append(symbol)
snapshot(browser)
return False
示例10: retry_take_screenshot
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def retry_take_screenshot(browser, symbol, interval, chart_only, tpl_strftime, retry_number=0):
if retry_number + 1 == config.getint('tradingview', 'create_alert_max_retries'):
log.info('trying again ({})'.format(str(retry_number + 1)))
refresh(browser)
try:
input_symbol = find_element(browser, css_selectors['input_symbol'])
set_value(browser, input_symbol, symbol)
input_symbol.send_keys(Keys.ENTER)
# time.sleep(DELAY_CHANGE_SYMBOL)
except Exception as e:
log.exception(e)
elif retry_number < config.getint('tradingview', 'create_alert_max_retries'):
log.info('trying again ({})'.format(str(retry_number + 1)))
return take_screenshot(browser, symbol, interval, chart_only, tpl_strftime, retry_number + 1)
else:
log.warn('max retries reached')
snapshot(browser)
示例11: retry
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def retry(browser, alert_config, timeframe, interval, symbol, screenshot_url, retry_number=0):
if retry_number < config.getint('tradingview', 'create_alert_max_retries'):
log.info('trying again ({})'.format(str(retry_number + 1)))
refresh(browser)
try:
# change symbol
input_symbol = find_element(browser, css_selectors['input_symbol'])
set_value(browser, input_symbol, symbol)
input_symbol.send_keys(Keys.ENTER)
time.sleep(DELAY_CHANGE_SYMBOL)
except Exception as err:
log.debug("Can't find {} in list of symbols" + str(symbol))
log.exception(err)
return create_alert(browser, alert_config, timeframe, interval, symbol, screenshot_url, retry_number + 1)
else:
log.error('Max retries reached.')
snapshot(browser)
return False
示例12: edit_cell
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def edit_cell(self, cell=None, index=0, content="", render=False):
"""Set the contents of a cell to *content*, by cell object or by index
"""
if cell is not None:
index = self.index(cell)
# # Select & delete anything already in the cell
# self.current_cell.send_keys(Keys.ENTER)
# if platform == "darwin":
# command(self.browser, 'a')
# else:
# ctrl(self.browser, 'a')
# self.current_cell.send_keys(Keys.DELETE)
self.browser.execute_script("IPython.notebook.get_cell(" + str(index) +
").set_text(" + repr(dedent(content)) + ")")
self._focus_cell(index)
if render:
self.execute_cell(self.current_index)
#
# Get info
#
示例13: execute_cell
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def execute_cell(self,
cell_or_index=None,
in_console=False,
expect_error=False):
if isinstance(cell_or_index, int):
index = cell_or_index
elif isinstance(cell_or_index, WebElement):
index = self.index(cell_or_index)
else:
raise TypeError("execute_cell only accepts a WebElement or an int")
self._focus_cell(index)
if in_console:
self.current_cell.send_keys(Keys.CONTROL, Keys.SHIFT, Keys.ENTER)
self._wait_for_done(-1, expect_error)
else:
self.current_cell.send_keys(Keys.CONTROL, Keys.ENTER)
self._wait_for_done(index, expect_error)
示例14: edit_prompt_cell
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def edit_prompt_cell(self,
content,
kernel='SoS',
execute=False,
expect_error=False):
# print("panel", self.prompt_cell.get_attribute("innerHTML"))
self.browser.execute_script("window.my_panel.cell.set_text(" +
repr(dedent(content)) + ")")
# the div is not clickable so I use send_key to get around it
self.prompt_cell.send_keys('\n')
self.select_console_kernel(kernel)
# self.prompt_cell.find_element_by_css_selector('.CodeMirror').click()
if execute:
self.prompt_cell.send_keys(Keys.CONTROL, Keys.ENTER)
self._wait_for_done(-1, expect_error=expect_error)
示例15: login
# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import ENTER [as 別名]
def login(self, email, password):
"""Log to facebook using email (str) and password (str)"""
url = "https://mbasic.facebook.com"
self.get(url)
email_element = self.find_element_by_name("email")
email_element.send_keys(email)
pass_element = self.find_element_by_name("pass")
pass_element.send_keys(password)
pass_element.send_keys(Keys.ENTER)
try:
self.find_element_by_name("xc_message")
print("Logged in")
return True
except NoSuchElementException as e:
print("Fail to login")
return False