本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait类的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait类的具体用法?Python WebDriverWait怎么用?Python WebDriverWait使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebDriverWait类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: getComments
def getComments(self):
"""
Get the comments of the current picture.
Returns:
A list of comments of the picture, where a <comment> is a shortlist
with the comment itself and the user of the comment.
"""
while True:
try:
more = WebDriverWait(self.driver, 1).until(EC.presence_of_element_located((By.ID, INFOS['viewMore'])))
more.click()
except:
break
soup = BeautifulSoup(self.driver.page_source, 'html.parser')
myComments = []
allComments = soup.find('ol', {'id': INFOS['picComments']}).find_all('li')
for comment in allComments:
try:
start = comment.find('div', {'class': 'h-mavatar'})
user = start.find('div').find('h3').find('a').getText()
comm = start.find('p', {'class': INFOS['comment']}).getText()
myComments.append([comm, user])
except:
pass
return myComments
开发者ID:alejandroscf,项目名称:20up,代码行数:28,代码来源:tntapi.py
示例2: is_clickable
def is_clickable(driver, full_xpath, xpath, timeout = 1):
try:
w = WebDriverWait(driver, timeout)
w.until(EC.element_to_be_clickable(('xpath',xpath)))
return XPathUtil.is_clickable(full_xpath)
except TimeoutException, ElementNotVisibleException:
return False
开发者ID:AntBean,项目名称:OpenWPM,代码行数:7,代码来源:webdriver_extensions.py
示例3: is_visible
def is_visible(driver, locator_type, locator, timeout=3):
try:
w = WebDriverWait(driver, timeout)
w.until(EC.visibility_of_element_located((locator_type, locator)))
return True
except TimeoutException:
return False
开发者ID:AntBean,项目名称:OpenWPM,代码行数:7,代码来源:webdriver_extensions.py
示例4: testDragAndDrop
def testDragAndDrop(driver, pages):
"""Copied from org.openqa.selenium.interactions.TestBasicMouseInterface."""
element_available_timeout = 15
wait = WebDriverWait(driver, element_available_timeout)
pages.load("droppableItems.html")
wait.until(lambda dr: _isElementAvailable(driver, "draggable"))
if not _isElementAvailable(driver, "draggable"):
raise AssertionError("Could not find draggable element after 15 seconds.")
toDrag = driver.find_element_by_id("draggable")
dropInto = driver.find_element_by_id("droppable")
holdDrag = ActionChains(driver) \
.click_and_hold(toDrag)
move = ActionChains(driver) \
.move_to_element(dropInto)
drop = ActionChains(driver).release(dropInto)
holdDrag.perform()
move.perform()
drop.perform()
dropInto = driver.find_element_by_id("droppable")
text = dropInto.find_element_by_tag_name("p").text
assert "Dropped!" == text
开发者ID:SeleniumHQ,项目名称:selenium,代码行数:26,代码来源:interactions_tests.py
示例5: check_scores
def check_scores(self, user, passwd, score, rating, questions):
mailstring = user + '@user.com'
email = WebDriverWait(self, 10).until(lambda self: self.browser.find_element_by_name("email"))
email.send_keys(mailstring)
password = self.browser.find_element_by_name("password")
#password.send_keys(USERS['PASSWORD2'])
password.send_keys(passwd)
submit_button = self.browser.find_element_by_css_selector("#submit_record__row input")
submit_button.click()
time.sleep(1)
scorestring = 'Score: ' + str(score)
ratingstring = 'Rating: ' + str(rating)
questionstring = 'Questions: ' + str(questions)
time.sleep(1)
body = WebDriverWait(self, 10).until(lambda self: self.browser.find_element_by_tag_name('body'))
self.assertIn(scorestring, body.text)
self.assertIn(ratingstring, body.text)
self.assertIn(questionstring, body.text)
self.url = ROOT + '/default/user/logout'
get_browser = self.browser.get(self.url)
开发者ID:DonaldMc,项目名称:gdms,代码行数:25,代码来源:test_q1_scorechck.py
示例6: _parse_statement
def _parse_statement(self):
wait = WebDriverWait(self.driver, 5)
try:
wait.until(lambda driver: driver.find_element_by_name('SetofPages'))
return self._parse_multipage()
except:
return self._parse_single_page()
开发者ID:kbeigan,项目名称:Westpac_account_parser,代码行数:7,代码来源:navigator.py
示例7: test3
def test3(self):
driver = self.driver
driver.get("http://www.google.com")
# find the element that's name attribute is q (the google search box)
inputElement = driver.find_element_by_name("q")
# type in the search
inputElement.send_keys("Cheese!")
# submit the form (although google automatically searches now without submitting)
inputElement.submit()
# the page is ajaxy so the title is originally this:
print driver.title
# we have to wait for the page to refresh, the last thing that seems to be updated is the title
try:
# element = WebDriverWait(driver, 10).until(EC.title_contains("cheese!"))
#element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "gs_htif0")))
#print element.text
# or
wait = WebDriverWait(driver, 10)
#element = wait.until(EC.presence_of_element_located((By.ID, "gs_htif0")))
element = wait.until(EC.element_to_be_clickable((By.ID,'gb_8')))
r = element.text
print "r", r
element1 = driver.find_element_by_xpath("//*[@id='gb_8']/span[2]")
element1.click()
title = driver.title
print title
except:
pass
开发者ID:ramyamango123,项目名称:test,代码行数:34,代码来源:list_webdriver.py
示例8: click_by_order_id
def click_by_order_id(self,key,id):
driver = self.conf.wxdriver
#import pdb;pdb.set_trace()
xpath = LC.ORDER[key] % str(id)
el = WebDriverWait(driver, WAIT_TIME).until(EC.element_to_be_clickable((By.XPATH, xpath)))
time.sleep(1)
el.click()
开发者ID:hyteer,项目名称:work,代码行数:7,代码来源:order.py
示例9: testExpectedConditionVisibilityOfElementLocated
def testExpectedConditionVisibilityOfElementLocated(self, driver, pages):
pages.load("javascriptPage.html")
with pytest.raises(TimeoutException):
WebDriverWait(driver, 0.7).until(EC.visibility_of_element_located((By.ID, 'clickToHide')))
driver.find_element_by_id('clickToShow').click()
element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.ID, 'clickToHide')))
assert element.is_displayed() is True
开发者ID:zhjwpku,项目名称:selenium,代码行数:7,代码来源:webdriverwait_tests.py
示例10: test_statsAddLink
def test_statsAddLink(self):
driver = self.driver
time.sleep(5)
# Load a different image in a different window
imageWindow2 = Util.load_image_different_window( self, driver, "aK.fits")
# Find and click on the Statistics window
statsWindow = driver.find_element_by_xpath("//div[@id='Statistics']")
self.assertIsNotNone( statsWindow, "Could not find statistics window")
ActionChains(driver).click( statsWindow ).perform()
# In Stastics context menu, open Link Settings
ActionChains(driver).context_click( statsWindow ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
# Add a link to the new image window
imageWindow2 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='CasaImageLoader2']")))
ActionChains(driver).move_to_element( statsWindow ).click( statsWindow ).drag_and_drop( statsWindow, imageWindow2).perform()
# Exit links
ActionChains(driver).move_to_element( statsWindow ).context_click( statsWindow ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()
# Move to the center of the image window so data appears in the Stats Window
ActionChains(driver).move_to_element( imageWindow2 ).perform()
# Sometimes text does not appear, therefore move mouse cursor
ActionChains(driver).move_by_offset( 100, 100 ).perform()
# Check that the Stastics window is not linked to the main image window
statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
statsText = statsText.get_attribute('textContent')
# Check that the Default sky text appears in the Stats Window
statsText = statsText.startswith("Default sky")
self.assertEqual( statsText, 0, "Statistics window should not be linked to multiple windows")
开发者ID:pfederl,项目名称:CARTAvis,代码行数:35,代码来源:tStatistics.py
示例11: Action
class Action():
def __init__(self):
self.desired_caps = {
"platformName": "Android",
"deviceName": "SM_G9500",
"appPackage": "com.tencent.mm",
"appActivity": ".ui.LauncherUI",
"noReset": True
}
self.driver = webdriver.Remote(DRIVER_SERVER, self.desired_caps)
self.wait = WebDriverWait(self.driver, TIMEOUT)
def entry(self):
# 点击进入搜索
search = self.wait.until(EC.presence_of_element_located((By.XPATH, '//android.widget.TextView[@content-desc="Search"]')))
search.click()
# 点击输入搜索内容
keyword = self.wait.until(EC.presence_of_element_located((By.ID, 'com.tencent.mm:id/hx')))
keyword.set_text(KEYWORD)
sleep(2)
# 点击搜索
TouchAction(self.driver).tap(x=1299, y=2605).perform()
sleep(2)
# 点击公众号
TouchAction(self.driver).tap(x=672, y=634).perform()
# 点击右上角人像
view_profile = self.wait.until(EC.presence_of_element_located((By.XPATH, '//android.widget.ImageButton[@content-desc="Chat Info"]')))
view_profile.click()
# 点击查看历史
view_history = self.wait.until(EC.presence_of_element_located((By.XPATH, '//android.widget.LinearLayout[8]//*[@resource-id="android:id/title"]')))
view_history.click()
sleep(3)
# TouchAction(self.driver).press(x=806, y=2500).move_to(x=806, y=2400).release().perform()
self.driver.swipe(FLICK_START_X, FLICK_START_Y + 960, FLICK_START_X, FLICK_START_Y)
sleep(1)
while True:
t = -450
for i in range(6):
try:
t += 440
sleep(1)
# 循环点击每篇文章图片 图片高度500px
# x, y根据自己手机屏幕来调整
TouchAction(self.driver).tap(x=1019, y=440+t).perform()
# 尝试再点击一次, 如果第一次点击到两个图片的中间, 并不会进入文章
# 图片与图片间隔180px
try:
TouchAction(self.driver).tap(x=1150, y=440+t+182).perform()
except:
pass
# 点击退出文章
sleep(2)
back = self.wait.until(EC.presence_of_element_located((By.ID, 'com.tencent.mm:id/i2')))
back.click()
except:
pass
sleep(1)
# 模拟拖动
self.driver.swipe(FLICK_START_X, FLICK_START_Y + 1500, FLICK_START_X, FLICK_START_Y)
开发者ID:pol9111,项目名称:tencent_WechatOffAcc_auto,代码行数:60,代码来源:spider.py
示例12: test_statsAnimation
def test_statsAnimation(self):
driver = self.driver
# Load a test image with animation
Util.load_image( self, driver, "Default")
# Move to the center of the image window so data appears in the Stats Window
imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
ActionChains(driver).move_to_element( imageWindow ).perform()
# Get the Statistics of the loaded image
statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
statsText = statsText.get_attribute('textContent')
# Click the forward animation button
forwardAnimateButton = driver.find_element_by_xpath("//div[@class='qx-toolbar']/div[@class='qx-button'][2]")
self.assertIsNotNone( forwardAnimateButton, "Could not find forward animation button")
driver.execute_script( "arguments[0].scrollIntoView(true);", forwardAnimateButton)
ActionChains(driver).click( forwardAnimateButton ).perform()
time.sleep(3)
# Move to the center of the image window so data appears in the Stats Window
imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
ActionChains(driver).move_to_element( imageWindow ).perform()
# Sometimes text does not appear, therefore move mouse cursor
ActionChains(driver).move_by_offset( 100, 100 ).perform()
# Get the Statistics of the loaded image
newStatsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
newStatsText = newStatsText.get_attribute('textContent')
# Check that the Statistics text changed when image in the image window was changed
self.assertNotEqual( newStatsText, statsText, "Stats text did not update during animation of the image")
开发者ID:pfederl,项目名称:CARTAvis,代码行数:34,代码来源:tStatistics.py
示例13: test_statsAddImage
def test_statsAddImage(self):
driver = self.driver
# Load a large test image.
Util.load_image( self, driver, "aH.fits")
# Move to the center of the image window so data appears in the Stats Window
imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
ActionChains(driver).move_to_element( imageWindow ).perform()
# Get the Statistics of the loaded image
statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
statsText = statsText.get_attribute('textContent')
# Load a different image in the same window
Util.load_image( self, driver, "aK.fits")
# Move to the center of the image window so data appears in the Stats Window
ActionChains(driver).move_to_element( imageWindow ).perform()
# Sometimes text does not appear, therefore move mouse cursor
ActionChains(driver).move_by_offset( 100, 100 ).perform()
# Get the Statistics of the loaded image
newStatsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
newStatsText = newStatsText.get_attribute('textContent')
# Check that the Statistics text changed when new image was loaded
self.assertNotEqual( newStatsText, statsText, "Stats text did not update when new image was loaded in main image window")
开发者ID:pfederl,项目名称:CARTAvis,代码行数:29,代码来源:tStatistics.py
示例14: wait_for_ajax_loading
def wait_for_ajax_loading(browser, class_name):
"""
Waits until the ajax loading indicator disappears.
"""
wait = WebDriverWait(browser, 30)
wait.until(lambda browser: len(browser.find_elements_by_class_name(
class_name)) == 0)
开发者ID:beaker-project,项目名称:beaker,代码行数:7,代码来源:webdriver_utils.py
示例15: getpage
def getpage(pageurl, load_marker):
"""
Load pageurl using selenium webdriver, read and return the pagesource
:param pageurl:
:return:
"""
# Start the webdriver and load page
wd = webdriver.Firefox()
#wd = webdriver.Chrome('/usr/local/Cellar/chromedriver/2.20/bin/chromedriver')
wd.get(pageurl)
# Wait for the dynamically loaded elements (load_marker) to show up
try:
dt = 3 # seconds
wait = WebDriverWait(wd, dt)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, load_marker)))
except TimeoutException:
wd.quit()
phtml = []
return phtml
except UnexpectedAlertPresentException:
wd.quit()
phtml = []
return phtml
# Read page and quit browser
phtml = wd.page_source
wd.quit()
return phtml
开发者ID:pdch,项目名称:blog_dynamics,代码行数:32,代码来源:html_selenium.py
示例16: setup_prevalence_chart
def setup_prevalence_chart(self, disease_progression_name, points, timeout=None):
"""Sets up the prevalence chart for the given Disease Progression. Returns the name of the relational function
that contains the prevalence chart."""
if timeout is None:
timeout = self.default_timeout
self.click_navbar_element('Disease Progression')
# Once the Disease Progression choices come up, click the desired one
WebDriverWait(self.selenium, timeout=timeout).until(
EC.visibility_of_element_located((By.LINK_TEXT, disease_progression_name))
).click()
# Once the latent period, etc. options come up, click to bring up the prevalence chart
prevalence_options = WebDriverWait(self.selenium, timeout=timeout).until(
EC.visibility_of_element_located((By.ID, 'id_disease_prevalence'))
)
prevalence_name = Select(prevalence_options).first_selected_option.text # remember its name
prevalence_options.click()
# Once the prevalence chart comes up, overwrite the old points with the new ones.
FunctionsPanel(
WebDriverWait(self.selenium, timeout=timeout).until(
EC.visibility_of_element_located((By.ID, 'functions_panel'))
)
).set_points(points)
return prevalence_name
开发者ID:NAVADMC,项目名称:ADSM,代码行数:27,代码来源:test_functional.py
示例17: __get__
def __get__(self, obj, type):
wdw = WebDriverWait(obj._driver, TIMEOUT)
wdw.until(
lambda driver: driver.find_elements(*self._locator),
'Element {} not found'.format(self._locator))
self._elements = obj._driver.find_elements(*self._locator)
return self._elements
开发者ID:tuticfruti,项目名称:tuticfruti_blog,代码行数:7,代码来源:web_element.py
示例18: loginForPhone
def loginForPhone(self, phoneName, passWord):
br = self.br
name = self.phoneName
password = self.passWord
message1 = 'python返回一个值不能全部读取'
element = loginElement.elementInit()
we = findElementAPI
# 判断页面元素是否加载完
wait = WebDriverWait(br, 10)
wait.until(EC.presence_of_all_elements_located, "页面元素未加载完全")
try:
we.switchFrame(br,element[1])
we.findXpath(br,element[2]).send_keys(name)
we.findXpath(br,element[4]).send_keys(password)
we.findXpath(br,element[5]).click()
except:
srcName = ('登录操作失败,请检查环境是否正常')
return srcName
# 判断登录是否弹出框
br.implicitly_wait(3)
try:
srcName = we.findXpath(br,element[7]).text
lenElement = 1
except:
lenElement = 0
if lenElement == 0:
try:
srcName = we.findXpath(br,element[8]).text
except:
message1 = '未找到元素'
return message1
return srcName, message1
开发者ID:icesdy115,项目名称:icesdy115.github.io,代码行数:33,代码来源:loginModule.py
示例19: isPresent
def isPresent(self):
time.sleep(60)
elem_projects_1 = self.driver.find_element_by_link_text("Projects")
elem_projects_1 = WebDriverWait(self.driver, 20).until(lambda driver : driver.find_element_by_link_text("Projects"))
elem_projects_1.click()
time.sleep(10)
self.assertIn(u"Projects", self.driver.title)
#print self.driver.find_element_by_xpath('//*[@id="snap"]/div/div[5]')
try:
snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
snap_png=snap_finish[3].get_attribute("style")
except:
print '1.catch the snap_finish error, and try again'
try:
snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
snap_png=snap_finish[3].get_attribute("style")
pass
except:
print '2. catch the snap_finish error, and try again'
snap_finish = WebDriverWait(self.driver, 20).until(lambda d : d.find_elements_by_class_name('processingstep'))
snap_png=snap_finish[3].get_attribute("style")
pass
print "snap_png is %s " % snap_png
finish_flag = re.search("step_ok_active", snap_png, re.IGNORECASE)
print "finish_flag is %s " % snap_finish
error_flag = re.search("step_error_active", snap_png, re.IGNORECASE)
#print "erro_flag is "+ not bool(error_flag)
if bool(error_flag):
return False
else:
if bool(finish_flag):
return True
开发者ID:AmyOrchid188,项目名称:Knowledge,代码行数:34,代码来源:krugle_junhui.py
示例20: test_answer
def test_answer(self):
for x in range(0,10):
#self.browser.find_element_by_xpath("(//input[@name='ans'])[2]").click()
toclick = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_xpath("(//input[@name='ans'])[2]"))
toclick.click()
urgency = self.browser.find_element_by_id("userquestion_urgency")
urgency.send_keys("9")
importance = self.browser.find_element_by_id("userquestion_importance")
importance.send_keys("10")
self.browser.find_element_by_id("userquestion_changecat").click()
category = self.browser.find_element_by_id("userquestion_category")
category.send_keys("Strategy")
self.browser.find_element_by_id("userquestion_changescope").click()
#activescope = self.browser.find_element_by_id("userquestion_activescope")
#activescope.select_by_visible_text("2 Continental")
#continent = self.browser.find_element_by_id("userquestion_continent")
#continent.select_by_visible_text("Africa (AF)")
#self.browser.find_element_by_id("userquestion_answerreason").clear()
self.browser.find_element_by_id("userquestion_answerreason").send_keys("test phase 4 user2")
#driver.find_element_by_css_selector("input.btn").click()
#answer.send_keys("1")
submit_button = self.browser.find_element_by_css_selector("#submit_record__row input")
submit_button.click()
body = WebDriverWait(self, 10).until(lambda self : self.browser.find_element_by_tag_name('body'))
self.assertIn('This question is in progress', body.text)
self.browser.find_element_by_xpath("//input[@value='Next Question']").click()
开发者ID:NewGlobalStrategy,项目名称:NetDecisionMaking,代码行数:34,代码来源:test_ph4_answerquestion.py
注:本文中的selenium.webdriver.support.ui.WebDriverWait类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论