本文整理汇总了Python中splinter.Browser.is_element_present_by_xpath方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_present_by_xpath方法的具体用法?Python Browser.is_element_present_by_xpath怎么用?Python Browser.is_element_present_by_xpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.is_element_present_by_xpath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_xpath [as 别名]
print(total, recvd, rate, eta)
file_name = "Lakme Channel" # change here
folder_name = "downloads\\" + file_name + "\\"
if not path.exists(folder_name): makedirs(folder_name)
if not path.exists("reports"): makedirs("reports")
fh = io.open("reports\\" + file_name + ".xls", "w", encoding='utf8')
fh.write(u"URL\tTitle\tAuthor\tUser Name\tCategory\tLikes\tDislikes\tDuration\tPublished\tRating\tView Count\tFile Name\n")
channel_url = "https://www.youtube.com/user/ILoveLakme/videos" # change here
chrome = Browser("chrome")
print "visit 'chrome://settings/content' to disable images"
sleep(20)
chrome.visit(channel_url)
sleep(5)
while chrome.is_element_present_by_xpath("//button[@class='yt-uix-button yt-uix-button-size-default yt-uix-button-default load-more-button yt-uix-load-more browse-items-load-more-button']"):
chrome.find_by_xpath("//button[@class='yt-uix-button yt-uix-button-size-default yt-uix-button-default load-more-button yt-uix-load-more browse-items-load-more-button']").click()
sleep(2)
sleep(5)
links = [a["href"] for a in chrome.find_by_xpath("//a[@class='yt-uix-sessionlink yt-uix-tile-link spf-link yt-ui-ellipsis yt-ui-ellipsis-2']")]
chrome.quit()
#flag = False
for url in links:
try:
video = pafy.new(url)
if video.length <= 120:
title = video.title # .encode('ascii', 'ignore')
print title
#if title == "rexona men in philippines": flag = True
#if flag:
author = video.author # .encode('ascii', 'ignore')
示例2: DashboardTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_xpath [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))
示例3: __init__
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_xpath [as 别名]
class Compass:
def __init__(self, username='', password='', outdir=''):
self._username = username
self._password = password
self._outdir = outdir
self._browser = None
self._record = None
def quit(self):
if self._browser:
self._browser.quit()
self._browser = None
def loggin(self):
prefs = {
"browser.download.folderList": 2,
"browser.download.manager.showWhenStarting": False,
"browser.download.dir": self._outdir,
"browser.helperApps.neverAsk.saveToDisk": "application/octet-stream,application/msexcel,application/csv"}
self._browser = Browser('chrome') #, profile_preferences=prefs)
self._browser.visit('https://compass.scouts.org.uk/login/User/Login')
self._browser.fill('EM', self._username)
self._browser.fill('PW', self._password)
time.sleep(1)
self._browser.find_by_text('Log in').first.click()
# Look for the Role selection menu and select my Group Admin role.
self._browser.is_element_present_by_name(
'ctl00$UserTitleMenu$cboUCRoles',
wait_time=30)
self._browser.select('ctl00$UserTitleMenu$cboUCRoles', '1253644')
time.sleep(1)
def wait_then_click_xpath(self, xpath, wait_time=30, frame=None):
frame = self._browser if frame is None else frame
while True:
try:
if frame.is_element_present_by_xpath(xpath, wait_time=wait_time):
frame.find_by_xpath(xpath).click()
break
else:
log.warning("Timeout expired waiting for {}".format(xpath))
time.sleep(1)
except:
log.warning("Caught exception: ", exc_info=True)
def wait_then_click_text(self, text, wait_time=30, frame=None):
frame = self._browser if frame is None else frame
while True:
if frame.is_text_present(text, wait_time=wait_time):
frame.click_link_by_text(text)
break
else:
log.warning("Timeout expired waiting for {}".format(text))
def adult_training(self):
self.home()
# Navigate to training page a show all records.
self.wait_then_click_text('Training')
time.sleep(1)
self.wait_then_click_text('Adult Training')
time.sleep(1)
self.wait_then_click_xpath('//*[@id="bn_p1_search"]')
def home(self):
# Click the logo to take us to the top
self.wait_then_click_xpath('//*[@alt="Compass Logo"]')
time.sleep(1)
def search(self):
self.home()
# Click search button
self.wait_then_click_xpath('//*[@id="mn_SB"]')
time.sleep(1)
# Click "Find Member(s)"
self.wait_then_click_xpath('//*[@id="mn_MS"]')
time.sleep(1)
# Navigate to training page a show all records.
with self._browser.get_iframe('popup_iframe') as i:
self.wait_then_click_xpath('//*[@id="LBTN2"]', frame=i)
time.sleep(1)
self.wait_then_click_xpath('//*[@class="popup_footer_right_div"]/a', frame=i)
time.sleep(1)
def lookup_member(self, member_number):
self.home()
# Click search button
self.wait_then_click_xpath('//*[@id="mn_SB"]')
time.sleep(1)
#.........这里部分代码省略.........