本文整理汇总了Python中splinter.Browser.find_by_css方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.find_by_css方法的具体用法?Python Browser.find_by_css怎么用?Python Browser.find_by_css使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.find_by_css方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0_http_browser_download
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def test_0_http_browser_download(self):
path = self.get_endpoint_path("HTTPServer")
url = "http://{0}/thredds/fileServer/{1}".format(self.data_node, path)
OpenID = "https://{0}/esgf-idp/openid/{1}".format(self.idp_node, self.username)
pf = {"browser.helperApps.neverAsk.saveToDisk": "application/x-netcdf, application/netcdf"}
browser = Browser("firefox", profile_preferences=pf)
browser.visit(url)
if browser.status_code.is_success() is True:
browser.quit()
return
browser.find_by_css("input.custom-combobox-input").fill(OpenID)
browser.find_by_value("GO").click()
browser.find_by_id("password").fill(self.password)
browser.find_by_value("SUBMIT").click()
# To Do only if user is not enrolled in a group
if browser.is_text_present("Group Registration Request"):
# Chosing First Registration Group
browser.find_by_id("button_1").click()
# Accepting License Agreement
browser.execute_script("myForm.submit();")
# Clicking on 'Download data button'
browser.find_by_id("goButton").click()
browser.quit()
示例2: buyprd
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def buyprd(u):
browser = Browser('firefox')
url = u
browser.visit(url)
# 10|10.5
browser.find_option_by_text(selectOption).first.click()
browser.find_by_name('commit').click()
if browser.is_text_present('item'):
print("Added to Cart")
else:
print("Error")
return
print "checking out"
browser.visit(checkoutUrl)
print "Filling Out Billing Info"
browser.fill("order[billing_name]", namefield)
browser.fill("order[email]", emailfield)
browser.fill("order[tel]", phonefield)
print "Filling Out Address"
browser.fill("order[billing_address]", addressfield)
browser.fill("order[billing_zip]", zipfield)
browser.select("order[billing_state]", statefield)
print "Filling Out Credit Card Info"
browser.select("credit_card[type]", cctypefield)
browser.fill("credit_card[number]", ccnumfield)
browser.select("credit_card[month]", ccmonthfield)
browser.select("credit_card[year]", ccyearfield)
browser.fill("credit_card[verification_value]", cccvcfield)
browser.find_by_css('.terms').click()
print "Submitting Info"
browser.find_by_name('commit').click()
sys.exit(0)
示例3: dosmth
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def dosmth(*arg):
#First argument True or False. When True use proxy in file 'fname', else use machine ip.
print arg
if not arg[0]:
browser = Browser()
browser.visit("http://www.ip-ping.ru/")
print browser.find_by_css("div.hc2").text
browser.quit()
else:
fname = arg[1]
with open(fname, 'r') as f:
reader = csv.reader(f, delimiter=":")
profiles = []
for ip, port in reader:
#print type(ip), port
profiles.append("{'network.proxy.http':'"+ip+"','network.proxy.http_port':"+port+",'network.proxy.type': 1}")
for profile in profiles:
print profile
profile = ast.literal_eval(profile)
browser = Browser(profile_preferences = profile)
browser.visit("http://www.ip-ping.ru/")
print browser.find_by_css("div.hc2").text
browser.quit()
示例4: google_login
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def google_login(user_name, password, code):
browser = Browser('firefox')
url = 'https://accounts.google.com/ServiceLogin'
browser.visit(url)
browser.find_by_id('Email').fill(user_name)
browser.find_by_id('next').click()
browser.find_by_id('Passwd').fill(password)
browser.find_by_id('signIn').click()
url1 = 'https://play.google.com/store?hl=jp'
browser.visit(url1)
browser.find_by_css('button.id-no-menu-change').click()
time.sleep(1)
browser.find_by_css('input.redeem-input-text-box').fill(code)
browser.find_by_id('id-redeem-ok-button').click()
time.sleep(2)
result = browser.find_by_css('div.redeem-invalid-code-msg').value
browser.quit()
return result
示例5: member_new
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def member_new(emails,link,password):
browser=Browser('chrome')
for n in emails:
email=n.rstrip()+"@sgsaas.net"
browser.visit(link);
browser.fill('age',"33");
browser.fill('firstname',"Sam");
browser.fill('lastname',"wang");
browser.find_by_name('email').last.fill(email);
browser.fill('telephone',3984020);
browser.fill('address_1',"Bukit Batok Avenue")
browser.fill('city',"Singapore");
browser.fill('postcode',658080);
browser.find_by_xpath('//select[@id="input-country"]//option[@value="188"]').click();
browser.find_by_xpath('//select[@id="input-zone"]//option[@value="4231"]').click();
browser.find_by_name('password').last.fill(password);
browser.fill('confirm',password);
browser.find_by_name('agree').click();
browser.find_by_css('.btn-primary').click();
sleep(1)
print email+" has registered!"
browser.quit()
return;
示例6: test_login
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def test_login(self):
with pyvirtualdisplay.Display():
browser = Browser()
browser.visit("http://ui:8080/accounts/login/")
browser.fill("login", "testuser")
browser.fill("password", "password")
browser.find_by_css(".btn-primary").click()
self.assertTrue(browser.find_by_text("Successfully signed in as testuser."))
示例7: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
""" Test setup """
self.browser = Browser("phantomjs")
# 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()
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()
def test_2_add_post (self):
self.browser.visit("http://127.0.0.1:8080")
print ("current url = ", self.browser.url)
self.browser.driver.set_window_size(1920, 1080)
self.browser.click_link_by_text('login')
print ("current url = ", self.browser.url)
self.browser.fill("email", "[email protected]")
self.browser.fill("password", "test")
button = self.browser.find_by_css("button[type=submit]")
button.click()
print (self.browser.url)
add_link=self.browser.find_link_by_partial_text('add')
add_link.click()
print (self.browser.url)
title="test_acceptance_add_post"
self.browser.fill("title", title)
now=datetime.datetime.now()
now=str(now)
self.browser.fill("content", now)
button = self.browser.find_by_css("button[type=submit]")
button.click()
print(self.browser.url)
new_post_appears=self.browser.is_text_present(title) and self.browser.is_text_present(now)
print ("new_post_appears = ", new_post_appears)
self.assertEqual(new_post_appears, True)
示例8: __scrape
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def __scrape(self, landing_page):
browser = Browser('chrome', executable_path='C:\Python27\Lib\site-packages\chromedriver_win32\chromedriver.exe', service_args=PROXIES)
# browser = Browser('phantomjs', service_args=PROXIES, user_agent='Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20130401 Firefox/21.0')
with browser:
template1 = True
browser.visit(landing_page)
time.sleep(2)
nav = [x for x in browser.find_by_css('a.nav') if (x.text == 'Jobs by Location' or x.text == 'By Location')]
if len(nav) > 0:
nav[0].click()
else:
template1 = False
link = browser.url
state_index = 1
city_index = 1
while True:
browser.visit(link)
if not template1:
nav = browser.find_by_css('#tabHeader')
nav = nav.find_by_css('a')
nav[1].click()
states = browser.find_by_name('search.stateList.value')
state_list = states.find_by_tag('option')
print state_list[state_index].text
state_list[state_index].click()
if state_list[state_index].text != 'choose one...':
element = 'cityList_' + state_list[state_index].text
cities = browser.find_by_id(element)
city_list = cities.find_by_tag('option')
city_list[city_index].click()
if city_list[city_index].text != 'choose one...':
print city_list[city_index].text, state_list[state_index].text
browser.find_by_id('cityStateSearch').click()
links = None
try:
links = browser.find_by_css('a.withBubble')
except:
pass
if len(links) > 0:
for i in links:
b = Browser('chrome', executable_path='C:\Python27\Lib\site-packages\chromedriver_win32\chromedriver.exe', service_args=PROXIES)
# b = Browser('phantomjs', service_args=PROXIES, user_agent='Mozilla/5.0 (Windows NT 6.1; rv:21.0) Gecko/20130401 Firefox/21.0')
with b:
b.visit(i['href'])
self.__navigate_pages(b)
else:
self.__navigate_pages(browser)
city_index += 1
if city_index == len(city_list):
city_index = 0
state_index += 1
if state_index == len(state_list):
break
else:
state_index += 1
示例9: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
# Test setup
self.browser = Browser("phantomjs")
#setup 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)
self.entry = Entry(title="test entry", content="test content")
session.add(self.entry)
session.commit()
self.process = multiprocessing.Process(target=app.run)
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()
def test_login_correct(self):
self.browser.visit("http://127.0.0.1:5000/login")
self.browser.fill("email", "[email protected]")
self.browser.fill("password", "test")
button = self.browser.find_by_css("button[type=submit]")
button.click()
#print(self.browser.url)
#print('asdf')
time.sleep(1)
self.assertEqual(self.browser.url, "http://127.0.0.1:5000/")
def test_login_incorrect(self):
self.browser.visit("http://127.0.0.1:5000/login")
self.browser.fill("email", "[email protected]")
self.browser.fill("password", "test")
button = self.browser.find_by_css("button[type=submit]")
button.click()
time.sleep(1)
self.assertEqual(self.browser.url, "http://127.0.0.1:5000/login")
#my acceptance test
def test_edit_entry_requires_login(self):
self.browser.visit("http://127.0.0.1:5000/entry/1/edit")
time.sleep(1)
self.assertEqual(self.browser.url, "http://127.0.0.1:5000/login?next=%2Fentry%2F1%2Fedit")
示例10: get_claim_code_from_server
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def get_claim_code_from_server():
browser = Browser('phantomjs', service_args=['--ignore-ssl-errors=true'])
browser.visit(ROOT_ADDRESS + "/merchant-login")
browser.fill_form({"email": USER_NAME, "password": PASSWORD})
browser.find_by_id("loginButton")[0].click()
time.sleep(5)
browser.visit(ROOT_ADDRESS + "/api-tokens")
browser.find_by_css(".token-access-new-button").find_by_css(".btn").find_by_css(".icon-plus")[0].click()
browser.find_by_id("token-new-form").find_by_css(".btn")[0].click()
return browser.find_by_css(".token-claimcode")[0].html
示例11: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
""" Test setup """
self.browser = Browser("phantomjs")
# Set up the tables in the database
Base.metadata.create_all(engine)
# Create an example user
self.user = models.User(name="Alice", email="[email protected]",
password=generate_password_hash("test"))
session.add(self.user)
session.commit()
self.process = multiprocessing.Process(target=app.run)
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()
def test_login_correct(self):
# self.browser.visit("http://0.0.0.0:8080/login")
self.browser.visit(DEVSERVERURL+"/login")
# print self.browser.html
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, DEVSERVERURL+"/")
def test_login_incorrect(self):
self.browser.visit(DEVSERVERURL+"/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, DEVSERVERURL+"/login")
def test_add_user(self):
self.browser.visit(DEVSERVERURL+"/add_user")
self.browser.fill("name", "dude")
self.browser.fill("email", "[email protected]")
self.browser.fill("password", "test")
button = self.browser.find_by_css("button[type=submit]")
button.click()
self.browser.visit(DEVSERVERURL+"/post/add")
self.assertEqual(self.browser.url, DEVSERVERURL+"/post/add")
示例12: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
""" Test setup """
self.browser = Browser("phantomjs")
# Set up the tables in the database
Base.metadata.create_all(engine)
# Create an example user
self.user = models.User(name="Alice", email="[email protected]",
password=generate_password_hash("test"))
session.add(self.user)
session.commit()
self.process = multiprocessing.Process(target=app.run)
self.process.start()
time.sleep(1)
def test_add_post(self):
log= logging.getLogger("unittest.TestCase")
################################## Login as Alice
#self.browser.visit("http://0.0.0.0:8080/login") # original line
self.browser.visit("http://127.0.0.1:5000/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://0.0.0.0:8080/") # original line
# self.assertEqual(self.browser.url, "http://127.0.0.1:5000/") # ask sam about this line
############################################ add a test post #####################
self.browser.visit("http://127.0.0.1:5000")
self.browser.click_link_by_partial_href('add')
self.browser.fill("title", "post test1 title")
self.browser.fill("content", "post test1 content")
button = self.browser.find_by_css("button[type=submit]")
button.click()
post_found = self.browser.find_by_tag('h1').value #cheated here - made template title h2. how do we access? index?
#post_found = self.browser.find_by_text('post test1 title').value - didnt work
log.debug( "FIRSTH1= %r", post_found )
self.assertEqual(post_found, "post test1 title")
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()
示例13: paginate
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
def paginate(self, url):
#browser = Browser("chrome")
browser = Browser("phantomjs")
browser.visit(url)
pages = [browser.html]
for i in range(10):
try:
browser.find_by_css(".PagerLinks > a")[-2].click()
pages.append(browser.html)
except:
break
return pages
示例14: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
""" Test setup """
self.browser = Browser("phantomjs")
# Set up the tables in the database
Base.metadata.create_all(engine)
# Create an example
self.user = models.User(name="Alice", email="[email protected]",
password=generate_password_hash("test"))
session.add(self.user)
session.commit()
self.process = multiprocessing.Process(target=app.run)
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()
def login(self, email, password):
self.browser.visit(TEST_SITE + "login")
self.browser.fill("email", email)
self.browser.fill("password", password)
button = self.browser.find_by_css("button[type=submit]")
button.click()
def test_login_correct(self):
self.login("[email protected]", "test")
self.assertEqual(self.browser.url, TEST_SITE)
def test_login_incorrect(self):
self.login("[email protected]", "test")
self.assertEqual(self.browser.url, TEST_SITE + "login")
def test_add_post(self):
self.login ("[email protected]", "test")
self.browser.visit(TEST_SITE + "post/add")
self.browser.fill("title", "acceptance test post 1")
self.browser.fill("content", "this is the content for the test case")
button = self.browser.find_by_css("button[type=submit]")
button.click()
self.assertEqual(self.browser.url, TEST_SITE)
self.assertTrue(
self.browser.is_text_present("acceptance test post 1"))
示例15: TestViews
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import find_by_css [as 别名]
class TestViews(unittest.TestCase):
def setUp(self):
""" Test Setup """
self.browser = Browser("phantomjs")
# 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()
# multiprocessing module gives you the ability to start and run other code simultaneously with your own scripts
# also allows you to communicate and control this code, by called methods such as start and terminate
# also provides features for implements concurrency in your applications
# in this test, you can't call app.run method as usual because this method is blocking and will stop the tests from running
# instead, you target which function to run
self.process = multiprocessing.Process(target=app.run, kwargs={"port": 8080})
self.process.start()
# time.sleep(1) in order to pause for a second to allow server to start
time.sleep(1)
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/")
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")
def tearDown(self):
""" Test Teardown """
# Remove the tables and their data from the database
# Kill the server
self.process.terminate()
session.close()
engine.dispose()
Base.metadata.drop_all(engine)
# Exit the browser
self.browser.quit()