本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait类的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait类的具体用法?Python WebDriverWait怎么用?Python WebDriverWait使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WebDriverWait类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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
示例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)
示例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()
示例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
示例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()
示例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
示例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")
示例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)
示例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")
示例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")
示例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)
示例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