本文整理汇总了Python中splinter.Browser.is_element_present_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_present_by_id方法的具体用法?Python Browser.is_element_present_by_id怎么用?Python Browser.is_element_present_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.is_element_present_by_id方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: court_booking_login
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
def court_booking_login(user, passwd):
"""
Create a new browser instance and login to the website
"""
browser = Browser()
browser.visit("https://courtbooking.bayclubs.com")
if browser.status_code != 200:
logging.error("court_booking_login: Unable to open court booking "
"website")
browser.quit()
return None
input_email = browser.find_by_id("InputEmail1")
input_email.fill(user)
input_passwd = browser.find_by_id("InputPassword1")
input_passwd.fill(passwd)
login_button = browser.find_by_id("loginButton")
login_button.click()
if browser.status_code != 200:
logging.error("court_booking_login: Error unable to login into court "
"booking website")
browser.quit()
return None
if browser.is_element_present_by_id("loginresult", wait_time=5):
logging.error("court_booking_login: Incorrect login credentials")
browser.quit()
return None
return browser
示例2: test_choose_stream_cloud_hidden
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
def test_choose_stream_cloud_hidden(self):
browser = Browser("firefox", extensions=["adblock.xpi"])
browser.visit("http://kinox.to/Stream/The_Big_Bang_Theory.html")
sleep(2)
overview_present = browser.is_element_present_by_id("ClickHelper", 5)
if overview_present:
overview_button = browser.find_by_id("ClickHelper")
overview_button.click()
overview_button.click()
stream = script.watchSeries("http://kinox.to/Stream/The_Big_Bang_Theory.html", None)
sleep(10)
stream.choose_stream_cloud(browser)
sleep(5)
result = browser.find_link_by_href("http://streamcloud.eu/")
assert result
else:
print "Test went wrong."
assert False
browser.quit()
示例3: __init__
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
class Session:
def __init__(self, browser, user):
self.browser = Browser(browser)
self.browser.visit('http://jizdenky.studentagency.cz/')
self.browser.fill_form({'passwordAccountCode': user['login'],
'password': user['password']})
self.browser.execute_script('window.scrollTo(0, 100)')
button = self.browser.find_by_value('Přihlásit').first
button.click()
self.user = user
self.log = logging.getLogger(__name__)
def go_search(self):
self.browser.visit('http://jizdenky.studentagency.cz/')
def search(self, task, date_return=None, is_open=False):
self.browser.find_by_id('hp_form_itinerar').first \
.find_by_xpath('div/input[@type="radio"]'
)[1 if date_return or is_open else 0].check()
for city, i in [(task.from_city, 1), (task.to_city, 2)]:
self.browser.find_by_css('input[tabindex="{}"]'.format(i)) \
.first.fill(city)
for item in self.browser.find_by_css('.ui-menu-item'):
link = item.find_by_tag('a')
if link.value.lower() == city.lower():
link.click()
break
self.browser.fill('departure:dateField', task.date)
if date_return:
self.browser.fill('returnDeparture:dateField', date_return)
if is_open:
self.browser.check('returnTicketOpen')
self.browser.find_option_by_text('ISIC').first.check()
self.browser.find_by_value('Vyhledat').first.click()
while self.browser.is_element_not_present_by_css('.left_column',
wait_time=1):
pass
items = self.browser.find_by_css('.left_column') \
.find_by_xpath('div/div/*')
connections = []
for item in items:
if item.tag_name == 'h2':
date_local = item.text.split(' ')[1]
elif item.tag_name == 'div' and item.has_class('routeSummary'):
assert date_local
if date_local != task.date:
break
connections.append(Connection(item))
return connections
def order_time(self, connection):
while True:
if connection.click():
self.browser
dialog = self.browser.find_by_css('[id^=_wicket_window]')
if dialog:
dialog.first.find_by_tag('button').click()
if self.browser.is_element_present_by_id('sumary_lines',
wait_time=1):
break
self.browser.find_by_id('sumary_lines') \
.first.find_by_tag('button') \
.first.click()
seats = {}
bus = self.browser.find_by_css('.seatsContainer')
if bus:
for seat in bus.first.find_by_css(
'.seatContainer:not([style*=blocked])'):
seats[int(seat.find_by_tag('div').first.html[:-1])] = seat
else:
bus = self.browser.find_by_css('.vehicle')
for seat in bus.first.find_by_css('.free, .selected'):
seats[int(seat.text[:-1])] = seat
return seats
def order_seat(self, seat):
if not seat.has_class('selected'):
seat.click()
for fs in self.browser.find_by_css('fieldset.topRoute'):
legend = fs.find_by_css('legend')
if legend and 'Pojištění' in legend[0].text:
for package in fs.find_by_css('.insurancePackageType'):
if 'nechci' in package.find_by_tag('label').text:
package.find_by_tag('input').click()
time.sleep(1)
submit = self.browser.find_by_css('[name^=buttonContainer]').first
interaction_type = submit.text
reserved = 'Rezervovat' in interaction_type
if not reserved:
submit.click()
time.sleep(1)
data = (self.user['first'],
self.user['last'],
self.user['email'],
self.user['phone'])
for item, value in zip(self.browser.find_by_id('passengerInfo')
.first.find_by_tag('input'),
data):
item.fill(value)
#.........这里部分代码省略.........
示例4: DataNodeTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
class DataNodeTestCase(LiveServerTestCase):
"""
A set of tests to test all interaction related to the creation and
deletion of nodes and relationships. Also, we test export the data in two
formats: gexf and csv.
"""
def setUp(self):
self.browser = Browser()
socket.setdefaulttimeout(30)
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
def tearDown(self):
logout(self)
self.browser.quit()
@classmethod
def tearDownClass(cls):
sleep(10) # It needs some time for close the LiverServerTestCase
super(DataNodeTestCase, cls).tearDownClass()
def test_data_node_addition(self):
create_graph(self)
create_schema(self)
create_type(self)
create_data(self)
# Check the node name
self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click()
text = self.browser.find_by_id('propertiesTitle').first.value
spin_assert(lambda: self.assertEqual(text, 'Properties'))
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkRight']/a").first.click()
self.browser.choose('confirm', '1')
self.browser.find_by_value('Continue').first.click()
text = self.browser.find_by_xpath("//div[@class='indent']/div").first.value
Graph.objects.get(name="Bob's graph").destroy()
spin_assert(lambda: self.assertEqual(text, 'Nodes: 0'))
def test_data_node_addition_rel_add_del(self):
create_graph(self)
create_schema(self)
create_type(self)
create_node(self, "Bob")
create_node(self, "Alice")
# We create a allowed relation
js_code = "$('a#schema-link')[0].click();"
self.browser.execute_script(js_code)
self.browser.find_by_id('allowedRelations').first.click()
self.browser.select('source', '1')
self.browser.find_by_name('name').fill("Bob's rel")
self.browser.select('target', '1')
self.browser.find_by_id('id_description').fill("This the allowed relationship for Bob's graph")
self.browser.find_by_value('Save Type').first.click()
spin_assert(lambda: self.assertEqual(
self.browser.title, "SylvaDB - Bob's graph"))
# We create the link between the nodes
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click()
self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click()
self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice')
self.browser.is_element_present_by_id("id_user_wait", 5)
self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click()
self.browser.find_by_value("Save Bob's type").first.click()
# Delete the relationship
self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click()
self.browser.find_by_xpath("//span[@class='all-relationships incoming-relationships i_bobs_rel1-relationships']//a[@class='delete-row initial-form floating']").first.click()
self.browser.find_by_value("Save Bob's type").first.click()
self.browser.find_link_by_href('/graphs/bobs-graph/').first.click()
text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value
spin_assert(lambda: self.assertEqual(text, "0 relationships"))
Graph.objects.get(name="Bob's graph").destroy()
def test_node_type_deletion_keeping_nodes(self):
create_graph(self)
create_schema(self)
create_type(self)
# Adding relationship to the type
self.browser.find_by_id('allowedRelations').first.click()
self.browser.select('source', '1')
self.browser.find_by_name('name').fill("Bob's rel")
self.browser.select('target', '1')
self.browser.find_by_id('id_description').fill(
'The loved relationship')
self.browser.find_by_value('Save Type').first.click()
text = self.browser.find_by_xpath(
"//div[@class='form-row indent']/label").first.value
spin_assert(lambda: self.assertNotEqual(text.find("Bob's rel"), -1))
# Creating nodes
create_node(self, 'Bob')
create_node(self, 'Alice')
# Creating relationship between nodes
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//td[@class='dataActions']/a[@class='dataOption list']").first.click()
self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click()
self.browser.find_by_xpath("//li[@class='token-input-input-token']/input").first.fill('Alice')
self.browser.is_element_present_by_id("id_user_wait", wait_time=5)
self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click()
self.browser.find_by_value("Save Bob's type").first.click()
self.browser.find_link_by_href('/graphs/bobs-graph/').first.click()
text = self.browser.find_by_xpath("//div[@class='flags-block']/span[@class='graph-relationships']").first.value
#.........这里部分代码省略.........
示例5: DashboardTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
class DashboardTestCase(LiveServerTestCase):
"""
These tests check basic functions of Sylva's dashboard.
"""
def setUp(self):
self.browser = Browser()
socket.setdefaulttimeout(30)
signup(self, "bob", "[email protected]", "bob_secret")
def tearDown(self):
logout(self)
self.browser.quit()
@classmethod
def tearDownClass(cls):
sleep(10) # It needs some time for close the LiverServerTestCase
super(DashboardTestCase, cls).tearDownClass()
def test_dashboard(self):
signin(self, "bob", "bob_secret")
spin_assert(lambda: self.assertEquals(self.browser.title, "SylvaDB - Dashboard"))
text = self.browser.find_by_xpath("//header[@class='global']/h1").first.value
spin_assert(lambda: self.assertEqual(text, "Dashboard"))
def test_dashboard_new_graph(self):
signin(self, "bob", "bob_secret")
create_graph(self)
Graph.objects.get(name="Bob's graph").destroy()
def test_dashboard_graph_preview(self):
"""
This test, after create a graph with data, checks the Sigma
visualization running a simple JavaScript code. This code gets the
current instance of Sigma and checks the data with Sylva JavaScript
object.
"""
signin(self, "bob", "bob_secret")
create_graph(self)
create_schema(self)
create_type(self)
create_data(self)
self.browser.find_link_by_href("/graphs/bobs-graph/").first.click()
self.browser.is_element_present_by_id("wait_for_js", 3)
js_code = """
var instance = sigma.instances(0);
var node = instance.graph.nodes()[0];
sylva.test_node_name = node.properties.Name;
"""
self.browser.execute_script(js_code)
text = self.browser.evaluate_script("sylva.test_node_name")
Graph.objects.get(name="Bob's graph").destroy()
spin_assert(lambda: self.assertNotEqual(text.find("Bob's node"), -1))
def test_automatic_tour(self):
"""
Thist test checks that the tour starts automatically after signup, only
once.
"""
self.browser.is_element_present_by_id("wait_for_cookie_tour", 3)
signin(self, "bob", "bob_secret")
exist = self.browser.is_element_present_by_xpath("//div[@class='joyride-content-wrapper']")
spin_assert(lambda: self.assertEqual(exist, True))
self.browser.visit(self.live_server_url + "/dashboard/")
exist = self.browser.is_element_present_by_xpath("//div[@class='joyride-content-wrapper']")
spin_assert(lambda: self.assertNotEqual(exist, True))
示例6: __init__
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
class HackFreeRice:
def __init__(self, browserType='chrome'):
self.correct = 0
self.incorrect = 0
self.readCredentials()
# Initialize splinter (other possible values include 'phantomjs' and 'firefox')
self.browser = Browser(browserType)
def initialize(self, verbose=False):
# Initialize until it is successful
while True:
if self.tryInitialize():
if verbose:
print 'Successfully initialized.'
break
def readCredentials(self, verbose=False):
# Read credentials from file
with open('config') as f:
username, password = f.readlines()
self.username = username.strip()
self.password = password.strip()
if verbose:
print 'Your username is %s' % self.username
print 'Your password is %s' % self.password
def tryInitialize(self, verbose=False):
# Open freerice
self.browser.visit('http://freerice.com/user/login')
# Close pop-up, if present
if self.browser.is_element_present_by_id('wfp-ew-dialog-close'):
if self.browser.find_by_id('wfp-ew-dialog-close').first.visible:
# Closed popup if present and visible
self.browser.find_by_id('wfp-ew-dialog-close').click()
# Login
self.browser.execute_script("$('#edit-name').val('%s')" % self.username)
self.browser.execute_script("$('#edit-pass').val('%s')" % self.password)
self.browser.execute_script("$('#edit-submit').click()")
already_logged_in = self.browser.is_text_present('Logout')
login_check_string = '%s has earned' % self.username
successful_login = self.browser.is_text_present(login_check_string)
if already_logged_in or successful_login:
if verbose:
print 'Successfully logged in!'
else:
if verbose:
print 'Login failed.'
return False
# Change subject to math
self.browser.execute_script("window.location.href = 'http://freerice.com/frapi/category_selected/18492'")
if self.browser.is_text_present('Multiplication Table'):
if verbose:
print 'Successfully navigated to Multiplication Table'
return True
else:
return False
def doQuestion(self, verbose=False):
# Close twitter solicitation, if present
self.browser.execute_script("$('#twt-skip').click()")
question_text = self.browser.evaluate_script("$('#question-title').text()")
question_text = question_text.split('loader')
question_text = ''.join(question_text)
if verbose:
print 'The question is: %s' % question_text
question_text = string.replace(question_text, ' x ', '*').strip()
if verbose:
print 'The code representation of the question is: %s' % question_text
question_answer = self.browser.evaluate_script(question_text)
if verbose:
print 'The answer is: %s' % question_answer
add_id_script = "$('a:contains(\"%s\").answer-item').attr('id', 'clickthisone')" % question_answer
if verbose:
print 'Script to add id is:', add_id_script
self.browser.execute_script(add_id_script)
self.browser.find_by_id('clickthisone').click()
if self.browser.is_text_present('Correct!'):
print 'Got the answer right. Yeah!'
self.correct += 1
else:
print 'Oops. Got that one wrong.'
self.incorrect += 1
print 'You have donated %s grains of rice!' % str(10 * self.correct)
示例7: BugTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_id [as 别名]
class BugTestCase(LiveServerTestCase):
"""
A set of tests to check the existence of bugs.
"""
def setUp(self):
self.browser = Browser()
socket.setdefaulttimeout(30)
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
def tearDown(self):
logout(self)
self.browser.quit()
Graph.objects.get(name="Bob's graph").destroy()
@classmethod
def tearDownClass(cls):
sleep(10) # It needs some time for close the LiverServerTestCase
super(BugTestCase, cls).tearDownClass()
def test_node_rel_count_one(self):
'''
This test show that reflexive outgoing `relationships` don't count if
there are more relationships.
'''
real_nodes = 0
real_rels = 0
create_graph(self)
create_schema(self)
# Creating a nodetype: "First"
self.browser.find_link_by_href(
'/schemas/bobs-graph/types/create/').first.click()
self.browser.find_by_name('name').first.fill("First")
self.browser.find_by_name('properties-0-key').first.fill('Name')
self.browser.find_by_name('properties-0-display').first.check()
self.browser.find_by_value('Save Type').first.click()
# Creating another nodetype: "Second"
self.browser.find_link_by_href(
'/schemas/bobs-graph/types/create/').first.click()
self.browser.find_by_name('name').first.fill("Second")
self.browser.find_by_name('properties-0-key').first.fill('Name')
self.browser.find_by_name('properties-0-display').first.check()
self.browser.find_by_value('Save Type').first.click()
self.browser.find_by_id('dataMenu').first.click()
# Creating an allowed relationship: "First -> First"
self.browser.find_by_id('allowedRelations').first.click()
self.browser.select('source', '1')
self.browser.find_by_name('name').fill('FirstToFirst')
self.browser.select('target', '1')
self.browser.find_by_value('Save Type').first.click()
# Creating an allowed relationship: "First -> Second"
self.browser.find_by_id('allowedRelations').first.click()
self.browser.select('source', '1')
self.browser.find_by_name('name').fill('FirstToSecond')
self.browser.select('target', '2')
self.browser.find_by_value('Save Type').first.click()
# Creating a node of the "First" type
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption new']")[0].click()
self.browser.find_by_name('Name').first.fill("First1")
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input").first.click()
real_nodes += 1
# Creating another node of the "First" type
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption new']")[0].click()
self.browser.find_by_name('Name').first.fill("First2")
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input").first.click()
real_nodes += 1
# Creating a node of the "Second" type
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption new']")[1].click()
self.browser.find_by_name('Name').first.fill("Second1")
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input").first.click()
real_nodes += 1
# Creating another node of the "Second" type
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption new']")[1].click()
self.browser.find_by_name('Name').first.fill("Second2")
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input").first.click()
real_nodes += 1
# Creating another node of the "Second" type
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption new']")[1].click()
self.browser.find_by_name('Name').first.fill("Second3")
self.browser.find_by_xpath("//span[@class='buttonLinkOption buttonLinkLeft']/input").first.click()
real_nodes += 1
# Editing the "First1" node
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption list']")[0].click()
self.browser.find_by_xpath("//td[@class='dataList']/a[@class='edit']").first.click()
# Adding more "FirstToSecond" relationship forms
self.browser.find_by_xpath("//a[@class='addButton inFormsets']")[1].click()
self.browser.find_by_xpath("//a[@class='addButton inFormsets']")[1].click()
# Adding the relationships
self.browser.find_by_xpath("//li[@class='token-input-input-token']/input")[0].fill('First2')
self.browser.is_element_present_by_id("id_user_wait", 3)
self.browser.find_by_xpath("//div[@class='token-input-dropdown']//li[@class='token-input-dropdown-item2 token-input-selected-dropdown-item']/b").first.click()
real_rels += 1
self.browser.find_by_xpath("//li[@class='token-input-input-token']/input")[1].fill('Second1')
#.........这里部分代码省略.........