本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait.find_elements_by_css_selector方法的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait.find_elements_by_css_selector方法的具体用法?Python WebDriverWait.find_elements_by_css_selector怎么用?Python WebDriverWait.find_elements_by_css_selector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.WebDriverWait
的用法示例。
在下文中一共展示了WebDriverWait.find_elements_by_css_selector方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_public_resources
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def test_public_resources(self):
# Check admin can make use of the public Test widget
self.login(username="admin", next="/admin/Workspace")
self.create_widget('Test')
# Check normuser also can make use of the public Test widget
self.login(username='normuser', next="/normuser/Workspace")
self.create_widget('Test')
# Also widget details can be accessed
with self.myresources_view as myresources:
myresources.wait_catalogue_ready()
myresources.search('Test')
with myresources.search_in_results('Test') as resource:
tab = resource.switch_tab('Change Log')
self.assertIsNotNone(tab, 'Missing change log tab')
changelog_contents = WebDriverWait(self.driver, 5).until(WEC.element_be_enabled((By.CSS_SELECTOR, '.se-notebook-tab-content.changelog'), base_element=resource.details))
headings = changelog_contents.find_elements_by_css_selector('h1')
self.assertEqual(len(headings), 1)
tab = resource.switch_tab('Documentation')
self.assertIsNotNone(tab, 'Missing documentation tab')
documentation_contents = WebDriverWait(self.driver, 5).until(WEC.element_be_enabled((By.CSS_SELECTOR, '.se-notebook-tab-content.documentation'), base_element=resource.details))
headings = documentation_contents.find_elements_by_css_selector('h1, h2')
self.assertEqual(len(headings), 2)
# But cannot be uninstalled by normal users
myresources.uninstall_resource('Test', expect_error=True)
示例2: test_basic_resource_details
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def test_basic_resource_details(self):
self.login()
with self.myresources_view as myresources:
myresources.wait_catalogue_ready()
myresources.search("Test")
with myresources.search_in_results("Test") as resource:
tab = resource.switch_tab("Change Log")
self.assertIsNotNone(tab, "Missing change log tab")
changelog_contents = WebDriverWait(self.driver, 5).until(
WEC.element_be_enabled(
(By.CSS_SELECTOR, ".se-notebook-tab-content.changelog"), base_element=resource.details
)
)
headings = changelog_contents.find_elements_by_css_selector("h1")
self.assertEqual(len(headings), 1)
tab = resource.switch_tab("Documentation")
self.assertIsNotNone(tab, "Missing documentation tab")
documentation_contents = WebDriverWait(self.driver, 5).until(
WEC.element_be_enabled(
(By.CSS_SELECTOR, ".se-notebook-tab-content.documentation"), base_element=resource.details
)
)
headings = documentation_contents.find_elements_by_css_selector("h1, h2")
self.assertEqual(len(headings), 2)
示例3: scrapeDate
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def scrapeDate(date,base,unique_keys):
# scraping link and additional data
link = base.replace('*', date) # add date to link
# print link
# print link
driver.get(link)
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "n_list-news")))
articles = element.find_elements_by_css_selector('#list_news_search > div.n_list-news > ul > li > div.txt > p')
# print len(articles)
for article in articles:
link = 'http://www.1tv.ru' +article.find_elements_by_css_selector('p>a')[0].get_attribute("href")
title = article.find_elements_by_css_selector('p>a')[0].text
# print link, title, date
scraperwiki.sql.save(unique_keys, {'link':link, 'date':date,'theme':title})
示例4: scrapeDate
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def scrapeDate(date,base,unique_keys, wD):
# scraping link and additional data
link = base.replace('*', date) # add date to link
# print link
driver.get(link)
try:
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "n_list-news")))
articles = element.find_elements_by_css_selector('#list_news_search > div.n_list-news > ul > li > div.txt > p')
print len(articles)
for article in articles:
link = 'http://www.1tv.ru' +article.find_elements_by_css_selector('p>a')[0].get_attribute("href")
title = article.find_elements_by_css_selector('p>a')[0].text.encode('utf8','ignore')
# print link, title, date
wD.writerow({'link':link, 'date':date,'theme':title})
except Exception, e:
print str(e)
driver.get_screenshot_as_file(screenShotPath)
示例5: WebDriverWait
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
except Exception as e :
print "Exception: top story %s" % e
try:
if findTopStoryOnly == False:
popular = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.ID,"most-shared")))
except Exception:
print "Exception: most shared"
browser.quit()
sys.exit()
try:
if findTopStoryOnly == False:
rowElements = popular.find_elements_by_css_selector('.text>h4>a')[:3]
#rowElements = WebDriverWait(browser, 20).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,".text>h4>a")))[:5]
except Exception as e:
print "Exception: failure in ROW ELEMENTS"
browser.quit()
sys.exit()
if findTopStoryOnly == False:
for row in rowElements[:]:
a = common_classes.Article(row.get_attribute("href"))
a.title = row.text.strip()
if len(a.url) > 2 and len(a.title) > 2:
rows.append(a)
示例6: main
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def main():
parser = argparse.ArgumentParser(description='shopping cart test.')
parser.add_argument("chromeDriverPath", help='specify the chrome driver path')
args = vars(parser.parse_args())
#Set Up Chrome Driver
driver=webdriver.Chrome(args['chromeDriverPath'])
#navigate Walmart.com
driver.get("http://www.walmart.com")
driver.maximize_window()
try:
WebDriverWait(driver, 10).until(EC.title_is(('Walmart.com: Save money. Live better.')))
except:
print 'Title Not found'
# Sign Up Pop Up window Handling
popUpDialogCloseButton=driver.find_element_by_xpath("//div[contains(@class,'Modal-outer js-responsive-modal-outer')]//button")
if popUpDialogCloseButton.is_displayed():
popUpDialogCloseButton.click()
#Logging into customer account
myAccountLink = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT,"My Account")))
myAccountLink.click()
driver.implicitly_wait(10)
# Entering the user Login Email Address
driver.find_element_by_css_selector("input[id='login-username']").send_keys("[email protected]")
# Enter the Password
driver.find_element_by_css_selector("input[id='login-password']").send_keys("[email protected]")
# Click the Sign In Button
driver.find_element_by_css_selector("button[class='btn login-sign-in-btn js-login-sign-in btn-block-max-s btn-block-max-s']").click()
#Explicit Wait Until User Name appears with Hello message
#Validate that the User is logged into correct account
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"span[class='js-account-display-name account-display-name']")))
#Locate Search Box and type iphone
searchTextField = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"input[id='search']")))
searchTextField.send_keys("iphone")
#Click the Search/ Submit Button
searchButton=driver.find_element_by_css_selector("button[type='submit']")
searchButton.click()
#Locate the entire list of search items to appear
header=WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"div[id='tile-container']")))
allProducts = header.find_elements_by_css_selector("div[class='js-tile js-tile-landscape tile-landscape']")
#Selecting the first product from the list
productSelected = allProducts[0]
productImageLink= productSelected.find_element_by_class_name("js-product-title")
#getting the name of the product
productName=productImageLink.get_attribute("innerHTML")
newProductName= getCleanProductName(productName)
#Click the Product Image Link
productImageLink.click()
#Handling out of stock Item
#out of stock
try:
outOfStockLabel= WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"p[class='price-oos']")))
print 'out of stock'
driver.quit()
except :
print 'In stock'
#User Navigated to the first next page and Handling the zipcode pop up if exists
try:
zipcodeTextfield=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"input[name='zipcode']")))
#Type the Zipcode in zicode text field
zipcodeTextfield.send_keys("94087")
#Locating and clicking the Check Button
checkButton=WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"button[class='btn btn-mini js-cell-coverage-check-btn']")))
checkButton.click()
#Locating and closing the zipcode popup
closeButton = driver.find_element_by_xpath("//div[contains(@class,'js-flyout-modal flyout-modal flyout-modal-wide')]//button")
closeButton.click()
except:
print 'No zipcode'
#Selecting a color field if exists.
try:
colorList=driver.find_element_by_css_selector("div[class='variants variants-swatches js-variants-swatches js-variants-collapsed variants-collapsed']")
colorChild=colorList.find_elements_by_css_selector("span[class='js-variant-swatch-container variant-swatch-container']")
colorChild[0].click() #Selecting the first color
except:
print ' no color option'
#.........这里部分代码省略.........
示例7: WebDriverWait
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
WAIT_SECONDS = 3
#"Top-Box-Office"
#MIN_SCORE = 74
try:
for sectionId in [OPENING_THIS_WEEK,BOX_OFFICE]:
primeRowElements = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.ID,sectionId)))
movies = None
isOpenningThisWeek = True
if sectionId == OPENING_THIS_WEEK:
movies = primeRowElements.find_elements_by_css_selector(".sidebarInTheaterOpening")
elif sectionId == BOX_OFFICE:
#continue
isOpenningThisWeek = False
movies = []
for index in range(1,MAX_RANKING_TOP_BOX_OFFICE):
movies.append(primeRowElements.find_element_by_xpath("tbody/tr[%s]" % index))
for movie in movies[:]:
intScore = 0
try:
scoreText = movie.find_element_by_css_selector(".tMeterScore")
score = re.sub(r'%$', "",scoreText.text.strip())
示例8: WebDriverWait
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
WEBSITE_URL = '%s/browse/picks/trending-now' % BASE
browser.get(WEBSITE_URL)
rowElements = []
MAX_RANKING = 5
FIRST_SECTION = ".subgrid"
'img.thumbnail'
try:
grid = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR,FIRST_SECTION)))
clips = grid.find_elements_by_css_selector(".item")[0:MAX_RANKING]
totalClips = len(clips)
counter = totalClips
#print "SIZE %s" % totalClips
for clip in clips[:]:
rowNum = totalClips - counter
clipElm = clip.find_element_by_xpath("//a[@data-model-position='%s']" % rowNum)
#http://www.hulu.com/watch/726517?playlist_id=1031
#replace the ?playlist_id=1031 with regex
a = common_classes.Article(re.sub(r'\?.+$', "",clipElm.get_attribute("href").strip()))
示例9: huoTicket
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
def huoTicket():
driver = webdriver.Chrome(executable_path=r'D:\devtools\chromedriver_win32\chromedriver.exe')
driver.maximize_window()
# 主页/首页
driver.get("http://piao.huo.com/index/city/shang%20hai")
cinemaClick = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "nav .icon03"))
)
cinemaClick.click() # 点击影院按钮
# 主页/影院
movie_mode = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.movie_mode"))
) # 等待左边的大列表加载结束
# 获取影院列表信息
elements = driver.find_elements_by_css_selector('li > div.con_media')
cinema_list = []
for e in elements:
cinema = e.find_element_by_css_selector('a.wordSearch')
print cinema.text # 影院名称
cinema_bttn = e.find_element_by_css_selector('a.ticket_btn')
url = cinema_bttn.get_attribute('href')
print url # 相对链接
# cinema_bttn.click() # 这会打开新页面
cdata = { 'name': cinema.text, 'url': url }
cinema_list.append(cdata)
# 测单个电影院
# cinema_list = [{ 'name': '', 'url': 'http://piao.huo.com/cinema/cinemaInfo/id/1162' }]
for c in cinema_list:
print ">>>>>>>>>>>>>", c['name']
driver.get(c['url'])
# movie_choice = driver.find_element_by_css_selector('div.cinchoice')
movie_choice = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.cinchoice"))
)
cho_det_rt = driver.find_element_by_css_selector('div.cho_det_rt')
index = 0
while True:
movie_choice = driver.find_element_by_css_selector('div.cinchoice')
movie_images = movie_choice.find_elements_by_css_selector('img')
if index >= len(movie_images):
break
# for img in movie_images:
# img.click()
# h3 = cho_det_rt.find_element_by_css_selector('h3')
# print h3.text
if not movie_images[index].is_displayed():
# a_r_btn = movie_choice.find_element_by_css_selector('a.r_btn')
a_r_btn = driver.find_element_by_css_selector('div.cie2 > a.r_btn')
a_r_btn.click()
continue
movie_images[index].click() # Error: Message: element not visible
driver.implicitly_wait(1) # seconds
h3 = cho_det_rt.find_element_by_css_selector('h3')
print h3.text
index += 1
driver.close()
示例10: findTopCommentAndTopNumber
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import find_elements_by_css_selector [as 别名]
#.........这里部分代码省略.........
print("pre 9")
try:
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH,"//a[@data-sort='popular']"))).click()
except Exception as e:
print "################### EXCEPTION a[@data-sort='popular']"
self.driver.switch_to.default_content();
return resultDict
##a data-role="username"
print("pre 10")
time.sleep(5)
##.updatable.count
topCommentNumber = 0
try:
elm = WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR,".updatable.count")))
text = elm.text
if isinstance(text, basestring) and len(text) > 0:
try:
topCommentNumber = int(text)
except Exception as e:
print "############# EXCEPTION fail to convert ot number"
except Exception as e:
print "#######################EXCEPTION Comment Number"
if topCommentNumber < VOTEUP_CRITERIA:
print "RETURNING Small Number"
self.driver.switch_to.default_content();
return resultDict
##.post-message
"""BROWSER UI: LOAD COMMENTS"""
"""Old page links should be gone"""
topComment = ''
print("pre 10")
try:
firstComment = WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR,".post-message")))
elms = firstComment.find_elements_by_css_selector('p')[0:2]
for elm in elms[:]:
if not elm.text:
try:
_elm = elm.find_element_by_css_selector('i')
except Exception as ee:
print("Exception: {0}".format(ee))
if _elm.text:
topComment = topComment + ' ' + _elm.text
else:
topComment = topComment + ' ' + elm.text
#print("topComment1: {0}".format(topComment))
except Exception as e:
print("Except: fail to find this element {0}".format(e))
self.driver.switch_to.default_content();
return resultDict
#print("topComment2: {0}".format(topComment))
topComment = re.sub(r'\\', "",topComment.strip())
#print("topComment3: {0}".format(topComment))
if len (topComment) < 10:
print "top comment"
self.driver.switch_to.default_content();
return resultDict
topComment = articleUtil.truncatedStringForRow(topComment);
self.driver.switch_to.default_content();
##.photo>img
##<img height="458" width="570" itemprop="image" style="width: 100% !important;height:auto !important" src="//cdn.theatlantic.com/static/newsroom/img/mt/2015/02/HillaryBaby/lead.jpg?njdcj8"/>
# if len(topComment) > WORDS_LIMIT:
# _topC = topComment[0:WORDS_LIMIT]
# tpC = re.sub(r'\.*$',"",_topC)
# topComment = "%s..." % tpC
##itemprop="datePublished"
##.content__dateline>time
#print "DONE Top Comment: %s TopCommentNumber: %s Timestamp: %s CommentNum: %s Title: %s" % (topComment, topCommentNumber, timeStamp, comNum, title)
resultDict = {'topComment':topComment, 'topCommentNumber':topCommentNumber,'timeStamp': timeStamp, 'numComments': comNum, 'title': title}
return resultDict