本文整理汇总了Python中selenium.webdriver.common.action_chains.ActionChains.send_keys_to_element方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.send_keys_to_element方法的具体用法?Python ActionChains.send_keys_to_element怎么用?Python ActionChains.send_keys_to_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.common.action_chains.ActionChains
的用法示例。
在下文中一共展示了ActionChains.send_keys_to_element方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _populate_field
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def _populate_field(self, locator, value):
field = self.selenium.get_webelement(locator)
self._focus(field)
if field.get_attribute("value"):
self._clear(field)
actions = ActionChains(self.selenium.driver)
actions.send_keys_to_element(field, value).perform()
示例2: write
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def write(self, text):
element = self.get_element()
input_field = element.find_element_by_xpath("./following-sibling::input")
actions = ActionChains(self.driver)
actions.click(on_element=element)
actions.send_keys_to_element(input_field, text)
actions.perform()
time.sleep(2)
示例3: test_actions_quantity
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_actions_quantity(self):
url = 'http://travelingtony.weebly.com/store/p4/Lope_Lunch_By_The_Pool.html'
driver.get(url)
# Locators
quantity_id = 'wsite-com-product-option-Quantity'
quantity_element = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_id(quantity_id))
actions = ActionChains(driver)
actions.send_keys_to_element(quantity_element, Keys.ENTER)
actions.send_keys_to_element(quantity_element, Keys.ARROW_DOWN)
actions.send_keys_to_element(quantity_element, Keys.ARROW_DOWN)
actions.perform()
示例4: test_sendKeys
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_sendKeys(self):
#Locators
searchFieldName = "q"
turtlePictureLocator = "//div[@title='Leatherback Turtle Picture']"
searchFieldElement = WebDriverWait(driver, 10).\
until(lambda driver: driver.find_element_by_name(searchFieldName))
actions = ActionChains(driver)
actions.send_keys_to_element(searchFieldElement, "Leatherback")
actions.send_keys_to_element(searchFieldElement, Keys.ENTER)
actions.perform()
WebDriverWait(driver, 10).\
until(lambda driver: driver.find_element_by_xpath(turtlePictureLocator))
示例5: test_send_keys
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_send_keys(self):
driver.get(self.url)
# Locators
search_field_name = 'q'
turtle_picture_locator = "//span[@title='Leatherback Turtle Picture']"
search_field_element = WebDriverWait(driver, 5).\
until(lambda driver: driver.find_element_by_name(search_field_name))
actions = ActionChains(driver)
actions.send_keys_to_element(search_field_element, "Leatherback")
actions.send_keys_to_element(search_field_element, Keys.RETURN)
actions.perform()
WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(turtle_picture_locator))
示例6: test_sendKeys
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_sendKeys(self):
#Locators
#searchFieldName = "q"
quantityNameLocator = "Quantity"
quantityElement = WebDriverWait(driver, 10).\
until(lambda driver: driver.find_element_by_name(quantityNameLocator))
actions = ActionChains(driver)
actions.send_keys_to_element(quantityElement, Keys.ENTER)
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ARROW_DOWN)
actions.perform()
time.sleep(5)
示例7: test_selectOption
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_selectOption(self):
#Locators
dropDownID = "wsite-com-product-option-Quantity"
dropDownElement = WebDriverWait(driver, 10).\
until(lambda driver: driver.find_element_by_id(dropDownID))
actions = ActionChains(driver)
actions.send_keys_to_element(dropDownElement, Keys.ENTER)
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ARROW_DOWN)
actions.perform()
# Just using time.sleep() so that you can see the last webdriver action. I do not recommend using it in your tests
time.sleep(10)
示例8: test_DropdownArrowDown
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_DropdownArrowDown(self):
## Locators
dropDownID = ".//*[@id='wsite-com-product-option-Quantity']"
dropDownElement = WebDriverWait(driver, 10).\
until(lambda driver: driver.find_element_by_xpath(dropDownID))
## Actions
actions = ActionChains(driver)
actions.send_keys_to_element(dropDownElement, Keys.ENTER)
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ARROW_DOWN)
actions.perform()
## Adding time.sleep() to allow user to see last webdriver action; use in tests otherwise not recommended
time.sleep(10)
示例9: process
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def process(self, driver):
print('[HANDLER]{0},{1},{2},{3}'.format(self.element, self.action, self.arg, self.debug))
element = driver.find_element_by_xpath(self.element)
ac = ActionChains(driver)
if self.action == self.ACTION_CLICK:
ac.click(element)
elif self.action == self.ACTION_MOVETO:
ac.move_to_element(element)
elif self.action == self.ACTION_SENDKEYS:
ac.send_keys_to_element(element, self.arg)
ac.perform()
return self.HANDLED
示例10: submit_search_request
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def submit_search_request(self):
try:
searchList = ['Honda', 'Neiman Marcus', 'P&G', 'Johnson & Johnson', 'Coca-Cola', 'Bank of America', 'Tiffany & Co.', 'Yahoo!', 'JP Morgan Chase & Co.', 'match.com']
global randSearchItem
randSearchItem = random.choice(searchList)
print "The random entered Ad name is %s." % randSearchItem
searchFieldElement = self.find_element("id",
HomePageMap['searchFieldId']
)
actions = ActionChains(self.driver)
actions.send_keys_to_element(searchFieldElement, randSearchItem)
actions.send_keys_to_element(searchFieldElement, Keys.ENTER)
actions.perform()
except:
raise IncorrectPageException
示例11: create_test_data
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def create_test_data(self):
pet_params = '?name=Doggy&breed=Pug&age=1'
veterinary_physician_params = '?username=veterinary_physician&first_name=Dr&middle_name=Veterinary&last_name=Physician&[email protected]'
with self.wait_for_page_load():
self.selenium.get(
'%s%s%s%s' % (
self.live_server_url, self.ADD_APPOINTMENT_URI, 'create_test_vet/', veterinary_physician_params))
with self.wait_for_page_load():
self.selenium.get('%s%s%s%s' % (
self.live_server_url, self.ADD_APPOINTMENT_URI, 'create_test_pet/', pet_params))
with self.wait_for_page_load():
self.selenium.get(
'%s%s' % (self.live_server_url, self.ADD_APPOINTMENT_URI))
vet_index = 0
pet_index = 0
submit_button = self.selenium.find_element_by_id('submit-id-submit')
pet_name_field = self.selenium.find_element_by_id('id_pet_name')
pet_option_fields = pet_name_field.find_elements_by_tag_name('option')
pet_description_field = self.selenium.find_element_by_id('id_pet_description')
visit_schedule_field = self.selenium.find_element_by_id('id_visit_schedule')
visit_description_field = self.selenium.find_element_by_id('id_visit_description')
veterinary_physician_field = self.selenium.find_element_by_id('id_veterinary_physician')
vet_option_fields = veterinary_physician_field.find_elements_by_tag_name('option')
for i, option in enumerate(vet_option_fields):
if (option.get_attribute('selected') is None):
vet_index = i
for i, option in enumerate(pet_option_fields):
if (option.get_attribute('selected') is None):
pet_index = i
vet_select_box = select.Select(veterinary_physician_field)
vet_select_box.select_by_value(vet_option_fields[vet_index].get_attribute('value'))
pet_select_box = select.Select(pet_name_field)
pet_select_box.select_by_value(pet_option_fields[pet_index].get_attribute('value'))
current_datetime = format(datetime.now() + timedelta(hours=25), '%m/%d/%Y %I:%M %p')
actions = ActionChains(self.selenium)
actions.send_keys_to_element(pet_description_field, 'Siberian Husky')
actions.send_keys_to_element(visit_schedule_field, current_datetime)
actions.send_keys_to_element(visit_description_field, 'Checkup')
actions.click(submit_button)
actions.perform()
with self.wait_for_page_load():
self.selenium.get(
'%s%s' % (self.live_server_url, self.VIEW_APPOINTMENTS_URI))
return {'scheduled_visit': current_datetime}
示例12: test_successful_appointment_scheduling
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
def test_successful_appointment_scheduling(self):
self.create_test_data()
webDriverWait = WebDriverWait(self.selenium, 10)
try:
vet_index = 0
pet_index = 0
submit_button = self.selenium.find_element_by_id('submit-id-submit')
pet_name_field = self.selenium.find_element_by_id('id_pet_name')
pet_option_fields = pet_name_field.find_elements_by_tag_name('option')
pet_description_field = self.selenium.find_element_by_id('id_pet_description')
visit_schedule_field = self.selenium.find_element_by_id('id_visit_schedule')
visit_description_field = self.selenium.find_element_by_id('id_visit_description')
veterinary_physician_field = self.selenium.find_element_by_id('id_veterinary_physician')
vet_option_fields = veterinary_physician_field.find_elements_by_tag_name('option')
for i, option in enumerate(vet_option_fields):
if (option.get_attribute('selected') is None):
vet_index = i
for i, option in enumerate(pet_option_fields):
if (option.get_attribute('selected') is None):
pet_index = i
vet_select_box = select.Select(veterinary_physician_field)
vet_select_box.select_by_value(vet_option_fields[vet_index].get_attribute('value'))
pet_select_box = select.Select(pet_name_field)
pet_select_box.select_by_value(pet_option_fields[pet_index].get_attribute('value'))
current_datetime = format(datetime.now() + timedelta(hours=25), '%m/%d/%Y %I:%M %p')
actions = ActionChains(self.selenium)
actions.send_keys_to_element(pet_description_field, 'Siberian Husky')
actions.send_keys_to_element(visit_schedule_field, current_datetime)
actions.send_keys_to_element(visit_description_field, 'Checkup')
actions.click(submit_button)
actions.perform()
success_message = webDriverWait.until(
EC.presence_of_element_located((By.CLASS_NAME, 'alert-success'))
)
self.assertEqual(success_message.text,
'Your request for an Appointment has been saved. Please wait for the Physician\'s Confirmation via email.')
except TimeoutException as e:
self.fail('Unable to Execute Test Properly')
示例13: web_slinger
# 需要导入模块: from selenium.webdriver.common.action_chains import ActionChains [as 别名]
# 或者: from selenium.webdriver.common.action_chains.ActionChains import send_keys_to_element [as 别名]
#.........这里部分代码省略.........
def click(self):
'''
Who doens't like clicking stuff?
'''
self.link.click()
def cookie_logger(self):
'''
Most consistent way of determining login status was found to be counting the number of cookies on the webdriver.
Used instead of status-specific button like "login" or "logout" because the buttons are always present albeit hidden and unclickable. Additionally, cookie checking is faster.
'''
if len(self.driver.get_cookies()) > 3:
self.logged_in = True
print 'Tastes like logged in'
else:
self.logged_in = False
print 'Tastes bad, like Im logged out'
def login(self):
'''
Logins in to gamoloco.com
Utilizes action chains to ensure proper ordering and timing of login events.
'''
if self.logged_in == False:
try:
lb = self.driver.find_element_by_xpath(self.login_button_xp)
emf = self.driver.find_element_by_xpath(self.login_email_field_xp)
pwf = self.driver.find_element_by_xpath(self.login_pw_field_xp)
self.login_actions = ActionChains(self.driver)
self.login_actions.click(lb)
self.login_actions.send_keys_to_element(emf,
os.environ.get('gamoloco_email'))
self.login_actions.send_keys_to_element(pwf,
os.environ.get('gamoloco_password'))
self.login_actions.send_keys(Keys.RETURN)
self.login_actions.perform()
except:
print 'action chain failed'
try:
self._click_login_submitter()
print 'clicked submitter again'
except:
print 'could not click submitter again'
# time.sleep(1)
# self.logged_in_check()
#
#
# print 'Not currently logged in. Attmpting to login'
# self._click_login_button()
# try:
# self._send_login_email()
# self._send_login_pw()
# try:
# self._click_login_submitter()
# print 'pushed submitter button again'
# except:
# print 'could not press submit button again'
# finally:
# self.logged_in_check()
#