本文整理汇总了Python中splinter.Browser.is_element_present_by_css方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_present_by_css方法的具体用法?Python Browser.is_element_present_by_css怎么用?Python Browser.is_element_present_by_css使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.is_element_present_by_css方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
def run(search_term):
first_name = search_term
browser = Browser()
#browser = Browser('zope.testbrowser', ignore_robots=True)
browser.visit('http://uoregon.edu/findpeople')
browser.fill('name', search_term)
browser.find_by_name('op').first.click()
if (len(browser.url) > len('http://uoregon.edu/findpeople/person/'+first_name+'/')) == 6:
print "Found"
#return results #FIXME: Add results grab
if browser.find_by_text('No results were found.') == True:
print "Not Found"
#return None
if browser.is_element_present_by_css('findpeople-list') == True:
print "Found Many"
#search options including middle initial
#if multiple results:
#search options including level
elif browser.is_element_present_by_css('findpeople-person') == True:
run(first_name)
else:
print "Not Found2"
示例2: test2
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
def test2(address, emm_stuff):
address_tmp = address.split(',')
address = "%s, %s, %s, %s"%(address_tmp[0],address_tmp[1],state,address_tmp[2])
try_again = True
while (try_again):
try:
f = open(filename,'a')
browser = Browser()
browser.visit('http://www.centurylink.com/')
browser.find_by_id('landingRes').first.click()
browser.find_by_id('home-speed-check').first.click()
browser.find_by_id('ctam_new-customer-link').first.click()
browser.is_text_present('Please enter your service address so we can show you accurate pricing product availability in your area', wait_time=5)
browser.fill('form.singleLineAddress', address)
browser.is_element_present_by_css('.ui-autocomplete.ui-menu.ui-widget.ui-widget-content.ui-corner-all', 15)
addressFound = browser.find_by_css('.ui-autocomplete.ui-menu.ui-widget.ui-widget-content.ui-corner-all li a').first.text
browser.find_by_css('.ui-autocomplete.ui-menu.ui-widget.ui-widget-content.ui-corner-all li a').first.click()
addressFound_formatted = re.sub(r'%s (\d+)'%(state), r'%s,\1'%(state), addressFound)
addressFound_formatted = re.sub(',USA', '', addressFound_formatted)
browser.is_text_present('Choose an Offer', wait_time=5)
try:
element = browser.find_by_css('.highestSpeed')
except:
element = browser.find_by_css('.dialupOnly')
extracted_speed_match = re.search("(\d+\.?\d?)",element.text)
output = re.sub('\s+',' ', addressFound_formatted+', '+extracted_speed_match.group(0))
print output
f.write(output+",%s,%s,%s\n"%(emm_stuff[0], emm_stuff[1],emm_stuff[2]))
browser.quit()
try_again=False
f.close()
except:
try_again = False
e = open('bad_addresses','a')
e.write(address+'\n')
e.close()
browser.quit()
示例3: crawl
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
def crawl(usr, pswd, out_path, driver="firefox"):
bsr = Browser(driver)
bsr.visit(URL_LOGIN)
bsr.find_by_id("phone1").fill(usr)
bsr.find_by_id("pswd").fill(pswd)
bsr.find_by_id("login").click()
if bsr.is_element_present_by_css("span.fw1.fs0.acnt"):
print "Successfully login!"
else:
print "Login failed, bye!"
bsr.visit("http://123.163.com/webmail/main/#mid=7")
while bsr.is_element_not_present_by_css("div.list-time"):
print "sleeping"
time.sleep(1)
bsr.find_by_css("span.iblock.icn-msg.list-icon.potr")[0].click()
page_num = get_page_num(bsr)
with open(out_path, "w") as out_f:
for pi in xrange(page_num):
print "Page %d/%d" % (pi+1, page_num)
date_lst = bsr.find_by_css("div.list-time")
date_msgs_lst = bsr.find_by_css("div.sms-item")
#HACK for scrolling the sms list down because of AJAX-style of showing sms
date_lst[-1].right_click()
msg_i = 0
for di in xrange(len(date_lst)):
date = date_lst[di].text.strip().split()[0]
msg_num_mat = re.findall(r"\(\s*(\d+).\s*\)", date_lst[di].text)
msg_num = int(msg_num_mat[0])
out_f.write("%s\t%d\n" % (date, msg_num))
for _ in range(msg_num):
name_obj = date_msgs_lst[msg_i].find_by_css("span.js-cnt.name")[0]
phone_obj = date_msgs_lst[msg_i].find_by_css("span.js-cnt.fc2")[0]
time_obj = date_msgs_lst[msg_i].find_by_css("div.fr.w6.js-cnt.bm-hack-w6")[0]
msg_obj = date_msgs_lst[msg_i].find_by_css("div.w4")[0]
type_obj = date_msgs_lst[msg_i].find_by_css("div.fl.w3.thide.fc5")[0]
out_f.write("%s\t%s\t%s\t%s\t%s\n" % (name_obj.html.encode("utf8"), \
phone_obj.html.strip("() ").encode("utf8"), \
time_obj.text.encode("utf8"), \
"0" if type_obj.visible else "1", \
msg_obj.text.encode("utf8")))
msg_i += 1
#next page
next_page_link = bsr.find_by_css("div.fr.pager")[0].find_by_tag("a")[2]
next_page_link.click()
示例4: main
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
def main(argv):
email = None
txtipt = None
socks = None
socksPort = None
try:
opts, args = getopt.getopt(argv, "hi:m:S:P:",["port=","socks=","input=","mail=","help"])
except:
print "Use --help for help"
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
print 'Usage %s options \n' % (os.path.basename(__file__))
print ' -h, --help This help'
print ' -m, --mail Your facebook login email'
print ' -i, --input Your input file name'
print ' -S, --socks Socks Proxy Address for Tor use'
print ' -P, --port Port Socks for Tor use'
sys.exit()
elif opt in ("-i","--input"):
txtipt = arg
elif opt in ("-m","--mail"):
email = arg
elif opt in ("-S","--socks"):
socks = arg
elif opt in ("-P","--port"):
socksPort = arg
if not email or not txtipt:
print 'Use --help for help'
sys.exit()
password = getpass.getpass()
if socks and socksProt:
proxy_settings = {
'network.proxy.type':1,
'network.proxy.socks': socks,
'network.proxy.socks_port': socksPort
}
browser = Browser('firefox',profile_preferences=proxy_settings)
else:
browser = Browser()
# with Browser() as browser:
browser.visit('https://m.facebook.com/')
browser.fill("email",email);
browser.fill("pass",password);
browser.find_by_name("login").click()
if browser.is_element_present_by_css('.login_error_box'):
print 'The email and password didn\'t work.'
sys.exit()
try:
fileipt = open(txtipt, 'r')
except:
sys.exit('Unable to open file %s' % txtipt)
for line in fileipt:
browser.visit(line)
addButton = browser.find_link_by_text('Add Friend')
if len(addButton) > 0:
addButton[0].click()
示例5: print
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
for i in addressl:
url=str(addressl[c])
# page=requests.get(url)
# browser.visit("http://ptv.vic.gov.au/journey#jpsearch%5Baction%5D=search&jpsearch%5Bfrom%5D%5Btype%5D=any&jpsearch%5Bfrom%5D%5Btext%5D=171+La+Trobe+St+(Melbourne+City)&jpsearch%5Bfrom%5D%5BoriginType%5D=29&jpsearch%5Bto%5D%5Btype%5D=any&jpsearch%5Bto%5D%5Btext%5D=995+Burke+Road+Camberwell&jpsearch%5Bto%5D%5BdestType%5D=29&jpsearch%5Bpreferences%5D%5BrouteType%5D=LEASTINTERCHANGE&jpsearch%5Bpreferences%5D%5BtrITDepMOTvalue%5D=10&jpsearch%5Bpreferences%5D%5BtrITDepMOT%5D=100&jpsearch%5Bpreferences%5D%5BchangeSpeed%5D=normal&jpsearch%5Bpreferences%5D%5Bundefined%5D=&jpsearch%5Bpreferences%5D%5BinclMOT_1%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_4%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_5%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_8%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_10%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_0%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_6%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_7%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_3%5D=on&jpsearch%5Bpreferences%5D%5BinclMOT_2%5D=on")
browser.visit(url)
print(c)
print(url)
browser.reload()
if browser.is_element_present_by_tag("optgroup", wait_time=10)==True:
# # print("has opt")
time.sleep(2)
browser.find_by_name("jpSubmit").first.click()
else:
print("does not have opt")
if browser.is_element_present_by_css("div.timespan", wait_time=10)==True:
time.sleep(2)
print("loaded1")
Origin=browser.find_by_id("JourneyPlanResults").first.find_by_tag("td")[0].text
Destination=browser.find_by_id("JourneyPlanResults").first.find_by_tag("td")[1].text
Depart=browser.find_by_id("JourneyPlanResults").first.find_by_tag("td")[2].text
Timespan=browser.find_by_css("div.timespan").first.text
else:
print("still has opt")
time.sleep(2)
browser.find_by_name("jpSubmit").first.click()
# # # browser.quit()
if browser.is_element_present_by_css("div.timespan", wait_time=10)==True:
time.sleep(2)
print("loaded2")
Origin=browser.find_by_id("JourneyPlanResults").first.find_by_tag("td")[0].text
示例6: line_login
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
def line_login(browser, user_name, password, code):
"""
lineに自動ログインして、パラメータのカードコードを入力し、チャージする。
チャージした結果を返す。
:param browser:ブラウザインスタンス
:param user_name:ログインユーザネーム
:param password:ログインパスワード
:param code:ギフトカードコード
:return:チャージ結果
"""
# ログインページを開く
browser = Browser('firefox')
url = 'https://store.line.me/home/'
browser.visit(url)
# ログインする
login_submit = browser.find_link_by_partial_href('login')
if login_submit:
login_submit.click()
else:
html_code = browser.html
return {
'code': 4,
'message': "サイト上に問題が発生しました。(サイトがアクセスできない、またはネットが遅すぎる可能性があります。)",
'htmlcode': html_code
}
username_input_field = browser.find_by_id('id')
password_input_field = browser.find_by_id('passwd')
login_submit = browser.find_by_value('Login')
if username_input_field and password_input_field and login_submit:
username_input_field.fill(user_name)
password_input_field.fill(password)
login_submit.click()
else:
html_code = browser.html
return {
'code': 4,
'message': "サイト上に問題が発生しました。(サイトがアクセスできない、またはネットが遅すぎる可能性があります。)",
'htmlcode': html_code
}
# ログイン画像認識があるかどうかチェックする
#captcha_image_field = browser.find_by_css('img.FnCaptchaImg')
#メールアドレスまたパスワードをチェックする
login_alert_field = browser.find_by_css('p.mdMN02Txt')
if browser.is_element_present_by_css('p.mdMN02Txt'):
result = login_alert_field.value
if result.find(unicode('The password you have entered is invalid, or you have not registered your email address with LINE.')) != -1:
html_code = browser.html
return {
'code': 2,
'message': 'メールアドレスまたはパスワードが正しくありません。',
'htmlcode': html_code
}
# チャージ画面に移動する
browser.find_by_text('Charge').click()
browser.windows.current = browser.windows[1]
browser.find_by_id('70002').click()
browser.execute_script("charge(this); return false;")
# チャージする
code_input_field = browser.find_by_id('FnSerialNumber')
code_input_field.fill(code)
time.sleep(9000)
browser.execute_script("javascript:doCharge(this);return false;")
result = browser.find_by_css('p.mdLYR11Txt01').value
browser.quit()
return result
示例7: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
''' Test setup '''
self.browser = Browser('phantomjs')
# if we don't set the window size, we won't be able to interact with UI that might
# be hidden because of our media queries with a smaller emulated window
self.browser.driver.set_window_size(1120, 550)
# set up the tables in the database
Base.metadata.create_all(engine)
# create an example user
self.user = User(name = 'capnmorgan', email = '[email protected]',
password = generate_password_hash('test'))
session.add(self.user)
session.commit()
# create a second example user
self.user = User(name = 'Bob', email = '[email protected]',
password = generate_password_hash('test'))
session.add(self.user)
session.commit()
self.process = multiprocessing.Process(target = app.run, kwargs = { 'port': 7000 })
self.process.start()
time.sleep(1)
def tearDown(self):
''' Test teardown '''
# remove the tables and their data from the database
self.process.terminate()
session.close()
engine.dispose()
Base.metadata.drop_all(engine)
self.browser.quit()
if os.environ['CONFIG_PATH'] != 'py_ferry.config.TravisConfig':
os.system('pgrep phantomjs | xargs kill')
def test_login_correct(self):
self.browser.visit('http://127.0.0.1:7000/login')
self.browser.fill('name', 'capnmorgan')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button.login')
button.click()
time.sleep(1)
self.assertEqual(self.browser.url, 'http://127.0.0.1:7000/games')
self.assertFalse(self.browser.is_element_present_by_css('button.login'))
self.assertTrue(self.browser.is_element_present_by_css('#games'))
def test_registration(self):
self.browser.visit('http://127.0.0.1:7000/register')
self.browser.fill('name', 'capn')
self.browser.fill('email', '[email protected]')
self.browser.fill('password', 'test')
self.browser.fill('passwordConfirm', 'test')
checkbox = self.browser.find_by_css('input.checkbox')
checkbox.click()
button = self.browser.find_by_css('button.register')
button.click()
time.sleep(1)
self.assertEqual(self.browser.url, 'http://127.0.0.1:7000/login')
self.assertTrue(self.browser.is_element_present_by_css('button.login'))
self.assertFalse(self.browser.is_element_present_by_css('button.register'))
self.browser.fill('name', 'capnmorgan')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button.login')
button.click()
time.sleep(1)
self.assertEqual(self.browser.url, 'http://127.0.0.1:7000/games')
self.assertFalse(self.browser.is_element_present_by_css('button.login'))
self.assertTrue(self.browser.is_element_present_by_css('#games'))
示例8: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
''' Test setup '''
self.browser = Browser('phantomjs')
# if we don't set the window size, we won't be able to interact with UI that might
# be hidden because of our media queries with a smaller emulated window
self.browser.driver.set_window_size(1120, 550)
# set up the tables in the database
Base.metadata.create_all(engine)
# create an example user
self.user = User(name = 'Alice', email = '[email protected]',
password = generate_password_hash('test'))
session.add(self.user)
session.commit()
# create a second example user
self.user = User(name = 'Bob', email = '[email protected]',
password = generate_password_hash('test'))
session.add(self.user)
session.commit()
self.process = multiprocessing.Process(target = app.run, kwargs = { 'port': 8080 })
self.process.start()
time.sleep(1)
def tearDown(self):
''' Test teardown '''
# remove the tables and their data from the database
self.process.terminate()
session.close()
engine.dispose()
Base.metadata.drop_all(engine)
self.browser.quit()
if os.environ['CONFIG_PATH'] != 'blog.config.TravisConfig':
os.system('pgrep phantomjs | xargs kill')
def test_login_correct(self):
self.browser.visit('http://127.0.0.1:8080/login')
self.browser.fill('email', '[email protected]')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button[type=submit]')
button.click()
self.assertEqual(self.browser.url, 'http://127.0.0.1:8080/')
self.assertFalse(self.browser.is_element_present_by_css('[href="/login"]'))
self.assertTrue(self.browser.is_element_present_by_css('[href="/logout"]'))
self.assertTrue(self.browser.is_element_present_by_css('[href="/entry/add"]'))
def test_login_incorrect(self):
self.browser.visit('http://127.0.0.1:8080/login')
self.browser.fill('email', '[email protected]')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button[type=submit]')
button.click()
self.assertEqual(self.browser.url, 'http://127.0.0.1:8080/login')
self.assertTrue(self.browser.is_element_present_by_css('[href="/login"]'))
self.assertFalse(self.browser.is_element_present_by_css('[href="/logout"]'))
self.assertFalse(self.browser.is_element_present_by_css('[href="/entry/add"]'))
def test_entries_dropdown(self):
self.browser.visit('http://127.0.0.1:8080')
dropdown = self.browser.find_by_id('entries').first
option = dropdown.find_by_text('50')
option.click()
self.assertEqual(self.browser.url, 'http://127.0.0.1:8080/page/1?limit=50')
def test_not_logged_in_user(self):
self.browser.visit('http://127.0.0.1:8080')
self.assertTrue(self.browser.is_element_present_by_css('[href="/login"]'))
self.assertFalse(self.browser.is_element_present_by_css('[href="/logout"]'))
self.assertFalse(self.browser.is_element_present_by_css('[href="/entry/add"]'))
def test_add_entry_while_not_logged_in_then_log_in_as_other_user_and_try_delete_and_edit(self):
test_title = 'A New Blog Post'
test_content = 'This is a test of a new blog post.'
self.browser.visit('http://127.0.0.1:8080/entry/add')
self.browser.fill('email', '[email protected]')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button[type=submit]')
button.click()
self.assertEqual(self.browser.url, 'http://127.0.0.1:8080/entry/add')
self.browser.fill('title', test_title)
self.browser.fill('content', test_content)
button = self.browser.find_by_css('button[type=submit]')
button.click()
self.assertEqual(self.browser.url, 'http://127.0.0.1:8080/')
self.assertTrue(self.browser.is_element_present_by_text(test_title))
self.assertTrue(self.browser.is_element_present_by_text(test_content))
logout_link = self.browser.find_by_css('[href="/logout"]').first
logout_link.click()
self.browser.visit('http://127.0.0.1:8080/logout')
login_link = self.browser.find_by_css('[href="/login"]').first
login_link.click()
self.browser.fill('email', '[email protected]')
self.browser.fill('password', 'test')
button = self.browser.find_by_css('button[type=submit]')
button.click()
#.........这里部分代码省略.........