本文整理汇总了Python中selenium.webdriver.firefox.webdriver.WebDriver.find_element_by_tag_name方法的典型用法代码示例。如果您正苦于以下问题:Python WebDriver.find_element_by_tag_name方法的具体用法?Python WebDriver.find_element_by_tag_name怎么用?Python WebDriver.find_element_by_tag_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.webdriver.WebDriver
的用法示例。
在下文中一共展示了WebDriver.find_element_by_tag_name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class Base:
@classmethod
def __init__(self, p_live_server_url):
self.live_server_url = p_live_server_url
self.driver = WebDriver()
@classmethod
def pause(self, p_seconds):
try:
WebDriverWait(self.driver, p_seconds).until(EC.title_is('pause'))
except:
pass
@classmethod
def grid_cell_doubleclick(self, p_element):
ActionChains(self.driver).double_click(p_element).perform()
@classmethod
def grid_cell_input(self, p_element, p_text):
self.grid_cell_doubleclick(p_element)
for k in range(0, len(p_element.text)):
p_element.send_keys(Keys.BACKSPACE)
p_element.send_keys(p_text)
@classmethod
def action_login(self, p_username, p_password, p_expectsuccess=True):
self.driver.get('{0}{1}'.format(self.live_server_url, '/login/'))
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
username_input = self.driver.find_element_by_id('txt_user')
username_input.send_keys(p_username)
password_input = self.driver.find_element_by_id('txt_pwd')
password_input.send_keys(p_password)
self.driver.find_element_by_xpath("//button[. = 'Sign in']").click()
if p_expectsuccess:
try:
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'header')))
except:
WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, 'div_alert_text')))
else:
try:
WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, 'div_alert_text')))
except:
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'header')))
@classmethod
def action_create_user(self, p_username, p_password, p_superuser):
self.driver.get('{0}{1}'.format(self.live_server_url, '/users/'))
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, 'body')))
assert 'OmniDB' in self.driver.title
self.driver.find_element_by_xpath("//button[. = 'New User']").click()
username_cell = self.driver.find_element_by_xpath("//tbody/tr[last()]/td[1]")
self.grid_cell_input(username_cell, p_username)
password_cell = self.driver.find_element_by_xpath("//tbody/tr[last()]/td[2]")
self.grid_cell_input(password_cell, p_password)
if p_superuser:
superuser_cell = self.driver.find_element_by_xpath("//tbody/tr[last()]/td[3]")
self.grid_cell_doubleclick(superuser_cell)
self.driver.find_element_by_tag_name('body').click()
self.driver.find_element_by_xpath("//button[. = 'Save Data']").click()
示例2: HomeTestCase
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class HomeTestCase(LiveServerTestCase):
def setUp(self):
self.browser = WebDriver()
self.browser.implicitly_wait(3)
def test_home(self):
self.browser.get('{0}{1}'.format(self.live_server_url,reverse('index')))
body = self.browser.find_element_by_tag_name('body')
self.assertIn('username', body.text)
user = ModelTestFactory.getUser(password='test')
username_input = self.browser.find_element_by_name("username")
username_input.send_keys(user.username)
password_input = self.browser.find_element_by_name("password")
password_input.send_keys('test')
self.browser.find_element_by_id('loginBtn').click()
示例3: RegisterTest
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class RegisterTest(LiveServerTestCase):
def setUp(self):
self.browser = WebDriver()
self.browser.implicitly_wait(5)
create_user('john','[email protected]','johnpassword')
steps_to_login(self.browser,self.live_server_url,'john','johnpassword')
def tearDown(self):
self.browser.quit()
def test_title(self):
open_page(self.browser, '/register/', self.live_server_url)
self.assertIn('Register Supernova', self.browser.title)
def steps_to_create_user(self,username,email,password):
open_page(self.browser, '/register/', self.live_server_url)
username_input = self.browser.find_element_by_name('username')
username_input.send_keys(username)
email_input = self.browser.find_element_by_name('email')
email_input.send_keys(email)
password_input = self.browser.find_element_by_name('password')
password_input.send_keys(password)
button_register = self.browser.find_element_by_name('submit')
button_register.click()
def test_register_correct(self):
self.steps_to_create_user('teste_django','[email protected]','teste_django')
register_correct_message = self.browser.find_element_by_tag_name('strong')
self.assertIn('thank you for registering!', register_correct_message.text)
def test_register_repeated_user(self):
self.steps_to_create_user('testedjangorepeated','[email protected]','testedjangorepeated')
self.steps_to_create_user('testedjangorepeated','[email protected]','testedjangorepeated')
register_repeated_message = self.browser.find_element_by_tag_name('li')
self.assertIn('User with this Username already exists.', register_repeated_message.text)
示例4: VisitorTest
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class VisitorTest(LiveServerTestCase):
"""
Test as a visitor (unregistered user)
"""
def setUp(self):
self.browser = WebDriver()
self.browser.implicitly_wait(3)
self.n1 = Node.objects.create(
title='TestNodeOne',
description='The first test node'
)
self.u1 = User.objects.create_user(
username='test1', email='[email protected]', password='111'
)
self.u2 = User.objects.create_user(
username='test2', email='[email protected]', password='222'
)
# Create 99 topics
for i in range(1, 100):
setattr(
self,
't%s' % i,
Topic.objects.create(
title='Test Topic %s' % i,
user=self.u1,
content_raw='This is test _topic __%s__' % i,
node=self.n1
)
)
def tearDown(self):
self.browser.quit()
def test_index(self):
self.browser.get(self.live_server_url+reverse('niji:index'))
body = self.browser.find_element_by_tag_name('body')
self.assertIn('niji', body)
def test_topic_page(self):
pass
def test_node_page(self):
pass
def test_pagination(self):
pass
示例5: LoginTest
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class LoginTest(LiveServerTestCase):
def setUp(self):
self.browser = WebDriver()
self.browser.implicitly_wait(5)
def tearDown(self):
self.browser.quit()
def test_title(self):
open_page(self.browser, '/login/', self.live_server_url)
self.assertIn('Login Supernova', self.browser.title)
def test_login_correct(self):
create_user('john','[email protected]','johnpassword')
steps_to_login(self.browser,self.live_server_url,'john','johnpassword')
self.assertIn('Index', self.browser.title)
def test_login_incorrect(self):
create_user('john','[email protected]','johnpassword')
steps_to_login(self.browser,self.live_server_url,'john1','johnpassword1')
login_incorrect = self.browser.find_element_by_tag_name('body')
self.assertIn('Invalid login details supplied.', login_incorrect.text)
def test_login_and_logout(self):
create_user('john','[email protected]','johnpassword')
steps_to_login(self.browser,self.live_server_url,'john','johnpassword')
login_successful = self.browser.find_element_by_tag_name('strong')
self.assertIn('Welcome to Supernova', login_successful.text)
link_logout = self.browser.find_element_by_link_text('Logout')
link_logout.click()
logout_sucessful = self.browser.find_element_by_tag_name('h1')
self.assertIn('Login to Supernova',logout_sucessful.text)
def test_login_logout_and_login(self):
create_user('john','[email protected]','johnpassword')
steps_to_login(self.browser,self.live_server_url,'john','johnpassword')
login_successful = self.browser.find_element_by_tag_name('strong')
self.assertIn('Welcome to Supernova', login_successful.text)
link_logout = self.browser.find_element_by_link_text('Logout')
link_logout.click()
logout_sucessful = self.browser.find_element_by_tag_name('h1')
self.assertIn('Login to Supernova',logout_sucessful.text)
steps_to_login(self.browser,self.live_server_url,'john','johnpassword')
login_successful = self.browser.find_element_by_tag_name('strong')
self.assertIn('Welcome to Supernova', login_successful.text)
示例6: LiveServerTest
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
#.........这里部分代码省略.........
elem = self.selenium.find_element_by_css_selector(selector)
if elem.tag_name == 'select':
self.select(selector, str(text_to_input))
else:
if clear:
elem.clear()
elem.send_keys(str(text_to_input))
self.wait(0.5)
def clear(self, selector):
elem = self.selenium.find_element_by_css_selector(selector)
elem.clear()
def click(self, elem_id):
elem = self.find_element_by_id(elem_id)
elem.click()
self.wait(0.5)
def click_by_css(self, element_css):
elem = self.selenium.find_element_by_css_selector(element_css)
elem.click()
self.wait(0.5)
def click_by_class_name(self, class_name):
elem = self.selenium.find_element_by_class_name(class_name)
elem.click()
self.wait(0.5)
def login(self, username, password):
self.visit('accounts/login')
username_input = self.selenium.find_element_by_id('id_username')
password_input = self.selenium.find_element_by_id('id_password')
submit_button = self.selenium.find_element_by_tag_name('button') # TODO make this more specific
username_input.send_keys(username)
password_input.send_keys(password)
submit_button.submit()
def visit(self, url_name, *args, **kwargs):
""" self.visit(name_of_url_as_defined_in_your_urlconf) """
self.selenium.get(self.get_full_url(url_name, *args, **kwargs))
if url_name in LiveServerTest.AJAX_WAIT:
self.wait(2)
self.assertTrue(self.selenium.execute_script('return (window.catalogue !== undefined ? catalogue._loaded : true)'),
'catalogue.js loading error')
def get_actual_filter_options(self):
option_selector = '%s option' % self.rf_id('filter')
return [x.get_attribute('value').encode('ascii') for x in self.selenium.find_elements_by_css_selector(option_selector)]
def get_expected_filter_options(self, data_set):
def gen_bp_pairs(objs):
for obj in objs:
yield ('B-' + str(obj.id) + '_apparent')
yield ('B-' + str(obj.id) + '_absolute')
normal_parameters = datasets.filter_choices(data_set.simulation.id, data_set.galaxy_model.id)
bandpass_parameters = datasets.band_pass_filters_objects()
return ['D-' + str(x.id) for x in normal_parameters] + [pair for pair in gen_bp_pairs(bandpass_parameters)]
def get_actual_snapshot_options(self):
option_selector = '%s option' % self.lc_id('snapshot')
return [x.get_attribute("innerHTML") for x in self.selenium.find_elements_by_css_selector(option_selector)]
def get_expected_snapshot_options(self, snapshots):
示例7: ActivitySeleleniumTests
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class ActivitySeleleniumTests(StaticLiveServerTestCase):
"""Selenium tests for the activity page"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not settings.DEBUG:
settings.DEBUG = True
if not settings.TESTING:
settings.TESTING = True
def setUp(self):
"""Handles login and things"""
call_command('flush', interactive=False, verbosity=0) # Clears db
call_command('loaddata', 'groups', commit=False, verbosity=0)
call_command('loaddata', 'school', commit=False, verbosity=0)
call_command('loaddata', 'permissions', commit=False, verbosity=0)
call_command('loaddata', 'auth_users', commit=False, verbosity=0)
call_command('loaddata', 'student', commit=False, verbosity=0)
call_command('loaddata', 'advisor', commit=False, verbosity=0)
call_command('loaddata', 'coordinator', commit=False, verbosity=0)
call_command('loaddata', 'activityoptions', commit=False, verbosity=0)
call_command('loaddata', 'learningobjectiveoptions', commit=False, verbosity=0)
call_command('loaddata', 'sample_entries', commit=False, verbosity=0)
self.selenium = WebDriver()
self.selenium.set_window_size(1024, 800)
self.selenium.get('{0}/{1}'.format(self.live_server_url, ''))
self.selenium.find_element_by_xpath('//*[@id="djHideToolBarButton"]').click()
self.selenium.implicitly_wait(10)
self.selenium.find_element_by_link_text('Login').click()
# Click on the student button in the gateway
self.selenium.find_element_by_xpath('/html/body/center/md-content/div/div/div[1]/a').click()
self.selenium\
.find_element_by_xpath("//img[@src='/static/journal/activities/img"
"/journal_sign.png']")
super()
def tearDown(self):
self.selenium.quit()
super()
def test_activity_form_back(self):
"""make sure the back button works"""
self.selenium.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/a").click()
self.selenium.find_element_by_name('activity_name').send_keys('Walking the cat')
self.selenium.find_element_by_name('activity_description').send_keys('Walking the cat around the neighborhood')
self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/form/div[2]/div[2]/input').send_keys('02/07/1990')
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[2]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[3]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_learned_objective"]/li[6]/label').click()
self.selenium.find_element_by_name('activity_adviser').send_keys('Cat')
self.selenium.find_element_by_name('advisor_phone').send_keys('1234567890')
self.selenium.find_element_by_name('advisor_email').send_keys('[email protected]')
self.selenium.find_element_by_link_text('Back').click()
self.selenium\
.find_element_by_xpath("//img[@src='/static/journal/activities/img"
"/journal_sign.png']")
def test_activity_form_error(self):
"""Tests to check errors on the activity form"""
self.selenium.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/a").click()
# self.selenium.find_element_by_name('activity_name').send_keys('')
self.selenium.find_element_by_name('activity_description').send_keys('Walking with huahua around the neighborhood')
self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/form/div[2]/div[2]/input').send_keys('02/07/1990')
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[2]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[3]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_learned_objective"]/li[6]/label').click()
self.selenium.find_element_by_name('activity_adviser').send_keys('Cat')
self.selenium.find_element_by_name('advisor_phone').send_keys('1234567890')
self.selenium.find_element_by_name('advisor_email').send_keys('[email protected]')
self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/form/div[6]/div/input').click()
self.selenium.find_element_by_name('activity_description').text
def test_activity_form(self):
"""Tests to ensure that activities page has all necessary elements."""
self.selenium.find_element_by_xpath("/html/body/div[1]/div[2]/div/div[1]/div/div[2]/div/a").click()
self.selenium.find_element_by_name('activity_name').send_keys('Walking the cat')
self.selenium.find_element_by_name('activity_description').send_keys('Walking the cat around the neighborhood')
self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/form/div[2]/div[2]/input').send_keys('02/07/1990')
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[2]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_activity_type"]/li[3]/label').click()
self.selenium.find_element_by_xpath('//*[@id="id_learned_objective"]/li[6]/label').click()
self.selenium.find_element_by_name('activity_adviser').send_keys('Cat')
self.selenium.find_element_by_name('advisor_phone').send_keys('1234567890')
self.selenium.find_element_by_name('advisor_email').send_keys('[email protected]')
self.selenium.find_element_by_xpath('/html/body/div[1]/div[2]/div[1]/form/div[6]/div/input').click()
self.selenium\
.find_element_by_xpath("//img[@src='/static/journal/activities/img"
"/journal_sign.png']")
body_text = self.selenium.find_element_by_tag_name('body').text
self.assertTrue('Walking the cat' in body_text)
self.assertTrue('Walking the cat around the neighborhood' in body_text)
示例8: PollsTest
# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import find_element_by_tag_name [as 别名]
class PollsTest(LiveServerTestCase):
def setUp(self):
user = User()
user.username = "admin"
user.email = "[email protected]"
user.set_password("adm1n")
user.is_active = True
user.is_superuser = True
user.is_staff = True
user.save()
self.browser = WebDriver()
self.browser.implicitly_wait(3)
def tearDown(self):
self.browser.quit()
def test_can_create_new_poll_via_admin_site(self):
# Gertrude opens her web browser, and goes to the admin page
self.browser.get(self.live_server_url + '/admin/')
# She sees the familiar 'Django administration' heading
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Django administration', \
body.find_element_by_id("header").text)
# She types in her username and passwords and hits return
username_field = self.browser.find_element_by_name('username')
username_field.send_keys('admin')
password_field = self.browser.find_element_by_name('password')
password_field.send_keys('adm1n')
password_field.send_keys(Keys.RETURN)
# her username and password are accepted, and she is taken to
# the Site Administration page
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Site administration', body.text)
# She now sees a couple of hyperlink that says "Polls"
polls_links = self.browser.find_elements_by_link_text('Polls')
self.assertEquals(len(polls_links), 2)
# The second one looks more exciting, so she clicks it
polls_links[1].click()
# She is taken to the polls listing page, which shows she has
# no polls yet
body = self.browser.find_element_by_tag_name('body')
self.assertIn('0 polls', body.text)
# She sees a link to 'add' a new poll, so she clicks it
new_poll_link = self.browser.find_element_by_link_text('Add poll')
new_poll_link.click()
# She sees some input fields for "Question" and "Date published"
body = self.browser.find_element_by_tag_name('body')
self.assertIn('Question:', body.text)
self.assertIn('Date published:', body.text)
# She types in an interesting question for the Poll
question_field = self.browser.find_element_by_name('question')
question_field.send_keys("How awesome is Test-Driven Development?")
# She sets the date and time of publication - it'll be a new year's
# poll!
date_field = self.browser.find_element_by_name('pub_date_0')
date_field.send_keys('01/01/12')
time_field = self.browser.find_element_by_name('pub_date_1')
time_field.send_keys('00:00')
# Gertrude clicks the save button
save_button = self.browser.find_element_by_css_selector("input[value='Save']")
save_button.click()
# She is returned to the "Polls" listing, where she can see her
# new poll, listed as a clickable link
new_poll_links = self.browser.find_elements_by_link_text(
"How awesome is Test-Driven Development?"
)
self.assertEquals(len(new_poll_links), 1)