本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait.get_attribute方法的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait.get_attribute方法的具体用法?Python WebDriverWait.get_attribute怎么用?Python WebDriverWait.get_attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.WebDriverWait
的用法示例。
在下文中一共展示了WebDriverWait.get_attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_pages
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def render_pages(self):
self.driver.set_window_size(1920, 1024)
print self.driver.get_window_size()
def execute(script, args):
self.driver.execute("executePhantomScript", {"script": script, "args": args})
self.driver.command_executor._commands["executePhantomScript"] = ("POST", "/session/$sessionId/phantom/execute")
pageno = 0
for page_url in self.page_urls:
self.driver.get(re.sub("&w=\d\d\d", "&w=1000", page_url))
pageno += 1
try:
img = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "img")))
width = img.get_attribute("width")
height = img.get_attribute("height")
except TimeoutException:
print page_url + " failed"
continue
execute("""this.paperSize = {width: '%spx', height: '%spx'};""" % (width, height), [])
execute("""this.zoomFactor = 0.8""", [])
file_name = "%s/page%d" % (self.title, pageno)
print file_name
render = 'this.render("{file_name}.pdf")'.format(file_name=file_name)
execute(render, [])
示例2: test_channelAnimatorBoundaryAnimation
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def test_channelAnimatorBoundaryAnimation(self):
driver = self.driver
# Open a test image so we have something to animate
Util.load_image( self, driver, "Default")
# Find and record the last valid value of the animation
self._getLastValue( driver, "Channel" )
lastChannelValue = self._getCurrentValue( driver, "Channel" )
# Find and click the lower spin box
lowerBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelLowerBoundSpin']/input")))
driver.execute_script( "arguments[0].scrollIntoView(true);", lowerBoundText)
lowerBoundText.click()
# Change the lower bound value
lowerBoundValue = Util._changeElementText(self, driver, lowerBoundText, 1)
# Find and click the upper spin box
upperBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelUpperBoundSpin']/input")))
driver.execute_script( "arguments[0].scrollIntoView(true);", upperBoundText)
upperBoundText.click()
# Change the upper bound value
upperBoundValue = Util._changeElementText( self, driver, upperBoundText, int(lastChannelValue)-1)
# Allow test image to animate for 2 seconds
self._animateForward( driver, "Channel" )
time.sleep(2)
# Check that the lower and upper bound values did not change during animation
lowerBound = lowerBoundText.get_attribute("value")
upperBound = upperBoundText.get_attribute("value")
self.assertEqual( int(lowerBound), int(lowerBoundValue), "Lower bound channel value changed during animation")
self.assertEqual( int(upperBound), int(upperBoundValue), "Upper bound channel value changed during animation")
示例3: parse_job_details
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def parse_job_details(browser, url) :
browser.get(url)
try :
if 'brassring' in url :
snippet = WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="ctl00_ProgressBar"]/table/tbody/tr[2]/td/table[4]')))
snippet = '<table width="92%" border="0" cellpadding="3" cellspacing="0" align="center" role="presentation">' + \
snippet.get_attribute('innerHTML') + \
'</table>'
elif 'appone' in url :
snippet = WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.XPATH, '//*[@id="JobDescription"]')))
snippet = '<table width="100%" cellpadding="3" id="JobDescription">' + \
snippet.get_attribute('innerHTML') + \
'</table>'
else :
snippet = ''
re_img = re.compile('<img.*?>')
snippet = re_img.sub('', snippet)
print snippet
return snippet
except StaleElementReferenceException:
print 'Selenium Error!'
return
except TimeoutException:
print 'Timeout Error!'
return
示例4: test_statsAddImage
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
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")
示例5: test_speaker_autocomplete
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def test_speaker_autocomplete(self):
# Put a person in the db for the autocomplete to find
speaker = Speaker.objects.create(name='Name', instance=self.instance)
# Type a name in
self.selenium.get('%s%s' % (self.live_server_url, '/speech/add'))
speaker_input = WebDriverWait(self.selenium, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@id='s2id_id_speaker']/child::a"))
)
speaker_input.click()
text_input = self.selenium.find_element_by_xpath('//div[@id="select2-drop"]//input')
text_input.send_keys('Na')
# Wait for autocomplete
WebDriverWait(self.selenium, 10).until(
lambda x: x.find_element_by_xpath('//div[@class="select2-result-label"]')
)
# First result is what was typed (for creating new entry), so click second
self.selenium.find_element_by_xpath('(//div[@class="select2-result-label"])[2]').click()
# Check it is selected
selection_element = self.selenium.find_element_by_xpath('//div[@id="s2id_id_speaker"]/descendant::span')
self.assertIn('Name', selection_element.text)
speaker_input = self.selenium.find_element_by_id("id_speaker")
self.assertTrue(speaker_input.get_attribute('value') == str(speaker.id))
# Check we can unselect it
self.selenium.find_element_by_xpath(
'//div[@id="s2id_id_speaker"]/descendant::abbr[@class="select2-search-choice-close"]').click()
speaker_input = self.selenium.find_element_by_id("id_speaker")
self.assertTrue(speaker_input.get_attribute('value') == "")
示例6: test_statsAnimation
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
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")
示例7: executeWaitAndGet
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def executeWaitAndGet(elem_exists, js_to_exec, elem_expected, elem_to_get, what):
global driver
if q(elem_exists, None):
driver.execute_script(js_to_exec)
try:
if elem_to_get is not None:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, elem_expected)))
elem = q(elem_to_get, None)[0]
else:
elem = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, elem_expected)))[0]
if what == "html":
return elem.get_attribute("innerHTML").encode("utf-8")
elif what == "text":
return elem.text.encode("utf-8")
elif what == "src":
return elem.get_attribute("src")
elif what == "len":
return len(elem)
elif what == "self":
return elem
else:
return ""
except TimeoutException as tex:
print "Timeout exception while waiting for : " + elem_expected
print "Exception msg : " + str(tex.message)
return ""
else:
return ""
示例8: save_shirt_positioning_and_ratio
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def save_shirt_positioning_and_ratio(self):
tryon_pic = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "shichuantpl_id4693")), 'Timed Out')
tryon_pic.click()
tryon_item3 = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "trypicid578")), 'Timed Out')
tryon_item3.click()
tryon_item_img = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.ID, "tryimgtmp578")), 'Timed Out')
plus = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@act='plus']")))
for x in range(0, 3):
plus.click()
down = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@act='wy_down']")))
for x in range(0, 3):
down.click()
item_attr = tryon_item_img.get_attribute("style")
before = self.parse_item_attributes(item_attr)
save_config = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.ID, "saveConfig")), 'Timed Out')
save_config.click()
self.webdriver.refresh()
tryon_pic_after = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "shichuantpl_id4693")), 'Timed Out')
tryon_pic_after.click()
tryon_item_after = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.CLASS_NAME, "trypicid578")), 'Timed Out')
tryon_item_after.click()
tryon_item_img_after = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.ID, "tryimgtmp578")), 'Timed Out')
item_attr_after = tryon_item_img_after.get_attribute("style")
after = self.parse_item_attributes(item_attr_after)
result = self.compare_item_attributes(before, after)
return result
示例9: findImage
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def findImage(self, articleTitle):
#video[0] get attribute('poster')
imageURL = ""
try:
elememt = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"video")))
imageURL = elememt.get_attribute("poster")
except Exception as e:
pass
if len(imageURL) == 0:
try:
elememt = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"img.maxed.responsive-img")))
imageURL = elememt.get_attribute("src")
except Exception as e:
return False
if len(imageURL) == 0:
return False
print("about to call getImageAndSave")
isSuccess = imageUtil.getImageAndSave(imageURL, articleTitle)
print("return from getImageAndSave")
return isSuccess
示例10: test_restFrequencyReset
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def test_restFrequencyReset(self):
driver = self.driver
timeout = selectBrowser._getSleep()
#Load a default image
Util.load_image( self, driver, "Orion.methanol.cbc.contsub.image.fits")
time.sleep(1)
self._showProfile( driver )
time.sleep(2)
#Open the profile settings to the Profiles tab.
profileWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowProfile']")))
ActionChains(driver).click( profileWindow ).perform()
Util.openSettings( self, driver, "Profile", True )
Util.clickTab( driver, "Profiles" )
#Set initial rest units to frequency in Hz and verify the
#rest frequency of the image is 229759000000.
frequencyUnitTypeRadio = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, 'profileFrequencyUnitType' ) ) )
ActionChains(driver).click( frequencyUnitTypeRadio ).perform()
unitsCombo = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, 'profileFrequencyUnits' ) ) )
driver.execute_script( "arguments[0].scrollIntoView(true);", unitsCombo)
ActionChains(driver).click( unitsCombo).perform()
ActionChains(driver).send_keys(Keys.ENTER).perform()
restFrequency = self._getRestFrequency(driver)
self.assertEqual( float(restFrequency), 229759000000, "Rest frequency was not correct")
time.sleep(10)
#Change the units to wavelength
waveUnitTypeRadio = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, 'profileWaveUnitType' ) ) )
driver.execute_script( "arguments[0].scrollIntoView(true);", waveUnitTypeRadio)
ActionChains(driver).move_to_element( waveUnitTypeRadio ).perform()
ActionChains(driver).click( waveUnitTypeRadio ).perform()
time.sleep(10)
#Verify the rest frequency has been converted to wavelength
restFrequencyText = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, 'profileRestFrequency' ) ) )
restFrequencyWave = str(restFrequencyText.get_attribute("value"))
print "Rest frequency wave=",restFrequencyWave
self.assertEqual( float(restFrequencyWave), 1.30481, "Rest frequency wave was not correct")
#Change the rest frequency
Util._changeElementText(self, driver, restFrequencyText, '1.30482' )
restFrequencyWave = str(restFrequencyText.get_attribute("value"))
print "Rest frequency wave2=", restFrequencyWave
self.assertEqual( float(restFrequencyWave), 1.30482, "Rest frequency wave was not correct")
#Reset the rest frequency and verify it matches the original value.
resetButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located( ( By.ID, 'profileRestReset' ) ) )
ActionChains(driver).click( resetButton).perform()
time.sleep( 1 )
restFrequencyReset = str(restFrequencyText.get_attribute("value"))
print "Rest frequency reset=",restFrequencyReset
self.assertEqual( restFrequency, restFrequencyReset, "Rest frequency was not reset correctly")
示例11: low_high
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def low_high(self):
elem_high = WebDriverWait(self.driver, 30, 0.1).until(
lambda d: d.find_element_by_css_selector(self.HIGH_LEVEL)
)
elem_low = WebDriverWait(self.driver, 30, 0.1).until(
lambda d: d.find_element_by_css_selector(self.LOW_LEVEL)
)
if not (elem_high.get_attribute("checked") or elem_low.get_attribute("checked")):
return False
return True
示例12: use_grow_icon
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def use_grow_icon(self):
self.choose_tryon_items()
tryon_item_img = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.ID, "tryimgtmp42")), 'Timed Out')
item_attr = tryon_item_img.get_attribute("style")
before = self.parse_item_attributes(item_attr)
up = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@act='plus']")))
for x in range(0, 3):
up.click()
item_attr = tryon_item_img.get_attribute("style")
after = self.parse_item_attributes(item_attr)
return (after['width'] > before['width'])
示例13: use_up_arrow
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def use_up_arrow(self):
self.choose_tryon_items()
tryon_item_img = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.ID, "tryimgtmp42")), 'Timed Out')
item_attr = tryon_item_img.get_attribute("style")
before = self.parse_item_attributes(item_attr)
up = WebDriverWait(self.webdriver, 10).until(EC.visibility_of_element_located((By.XPATH, "//button[@act='wy_up']")))
for x in range(0, 3):
up.click()
item_attr = tryon_item_img.get_attribute("style")
after = self.parse_item_attributes(item_attr)
diff = before['top']-after['top']
return (diff < 11 and diff > 9)
示例14: child_child_checked
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def child_child_checked(self):
button = WebDriverWait(self.driver, 30, 0.1).until(
lambda d: d.find_element_by_css_selector(self.COUNTRY[5])
)
button.click()
element = WebDriverWait(self.driver, 30, 0.1).until(
lambda d: d.find_element_by_css_selector(self.CHILD)
)
print element.get_attribute("class")
if not ("checked" in (element.get_attribute("class"))):
return False
return True
示例15: test_animatorChangeLink
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import get_attribute [as 别名]
def test_animatorChangeLink(self):
driver = self.driver
browser = selectBrowser._getBrowser()
timeout = 2*selectBrowser._getSleep()
#Load an image with more than one channel so the channel
#animator will appear
imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
Util.load_image( self, driver, "Default")
# Enable the animation window
animWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowAnimation']")))
ActionChains(driver).click( animWindow ).perform()
# Remove Animator link to the image window
linkMenuButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Links...']")))
ActionChains(driver).click( linkMenuButton ).perform()
Util.remove_main_link( self, driver, imageWindow)
# Load an image in a different window
imageWindow2 = Util.load_image_different_window( self, driver, "Orion.methanol.cbc.contsub.image.fits")
# Change link to second image
animWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "ChannelAnimatorUpperBound")))
ActionChains(driver).double_click( animWindow ).perform()
linkMenuButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Links...']")))
ActionChains(driver).click( linkMenuButton ).perform()
Util.link_second_image( self, driver, imageWindow2)
# Find and click the upper spin box
upperBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelUpperBoundSpin']/input")))
driver.execute_script( "arguments[0].scrollIntoView(true);", upperBoundText)
# Check that the animator updates to the second image
upperBound = upperBoundText.get_attribute("value")
self.assertNotEqual( int(upperBound), 0, "Channel animator did not update to second image values")
# Show the image animator by loading a second image in the second window
Util.load_image_windowIndex( self, driver, "aH.fits", 2)
# Find and click the upper spin box
imageUpperBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ImageUpperBoundSpin']/input")))
driver.execute_script( "arguments[0].scrollIntoView(true);", imageUpperBoundText)
# Get the image upper spin value
imageCount = imageUpperBoundText.get_attribute("value")
print "Animator image count ", imageCount
# Check that the Image Animator updates
self.assertEqual( int(imageCount), 1, "Image Animator did not update after image was linked")