本文整理汇总了Python中selenium.webdriver.common.by.By.CLASS_NAME属性的典型用法代码示例。如果您正苦于以下问题:Python By.CLASS_NAME属性的具体用法?Python By.CLASS_NAME怎么用?Python By.CLASS_NAME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类selenium.webdriver.common.by.By
的用法示例。
在下文中一共展示了By.CLASS_NAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadmap
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def loadmap(self):
'''
loadmap()
Creates a browser object and loads the webpage.
It sets up the map to the proper zoom level.
Returns the browser on success, None on fail.
'''
browser = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '20000'})
browser.set_window_size(abovetustin_image_width, abovetustin_image_height)
print("getting web page {}".format(self.url))
browser.set_page_load_timeout(15)
browser.get(self.url)
# Need to wait for the page to load
timeout = g_request_timeout
print ("waiting for page to load...")
wait = WebDriverWait(browser, timeout)
element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'vrsMenu')))
self.browser = browser
示例2: getNextPicture
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def getNextPicture(self):
"""
Get the next picture to the given picture.
"""
try:
next = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.ID, INFOS['next'])))
try:
self.driver.execute_script("document.getElementById('" + INFOS['next'] + "').focus();")
except:
pass
finally:
next.click()
except:
try:
next = WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, INFOS['next3'])))
next.click()
except:
pass
示例3: get_privacy
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def get_privacy(driver, package_name):
try:
url = "https://play.google.com/store/apps/details?id={0}&hl=en".format(package_name)
driver.get(url)
driver.maximize_window()
driver.find_element_by_link_text("View details").click()
tmp = (By.CLASS_NAME, "fnLizd")
WebDriverWait(driver, 20).until(EC.presence_of_element_located(tmp))
page_source = driver.page_source
if "send SMS messages" in page_source:
print("找到含有SMS权限的APP: {0}".format(package_name))
with open("privacy_with_sms.txt", "a+") as f:
f.write(package_name + "\n")
return package_name
return False
except Exception as e:
print(e)
return False
示例4: try_submit
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def try_submit(self, err=None, ok=None, message=None):
BY_ORG_DASHBOARD = (By.CLASS_NAME, 'organization-dashboard')
fields = self.get_fields()
sel = BY_ORG_DASHBOARD if err is None else self.test.BY_FIELD_ERROR
self.test.click_through(fields['add'], sel, screenshot='tst')
fields = self.get_fields()
if err is not None:
for f in err:
try:
self.test.assert_field_has_error(fields[f], message)
except AssertionError:
raise AssertionError(
'Field "' + f + '" should have error, but does not'
)
if ok is not None:
for f in ok:
try:
self.test.assert_field_has_no_error(fields[f])
except AssertionError:
raise AssertionError(
'Field "' + f + '" should not have error, but does'
)
示例5: try_submit
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def try_submit(self, err=None, ok=None, message=None):
BY_MEMBER_PAGE = (By.CLASS_NAME, 'org-member-edit')
fields = self.get_fields()
sel = BY_MEMBER_PAGE if err is None else self.test.BY_FIELD_ERROR
self.test.click_through(fields['submit'], sel, screenshot='tst')
if err is not None:
fields = self.get_fields()
for f in err:
try:
self.test.assert_field_has_error(fields[f], message)
except AssertionError:
raise AssertionError(
'Field "' + f + '" should have error, but does not'
)
示例6: try_cancel_and_close
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def try_cancel_and_close(self,
click_on_button,
fill_inputbox=None,
check_input=None):
"""
Check to make sure that the close and cancel buttons work on modals.
"""
close_buttons = ['btn-link', 'close']
for close in close_buttons:
if fill_inputbox:
fill_inputbox()
cancel = self.link(close)
self.click_through_close(
cancel, (By.CLASS_NAME, 'modal-backdrop'))
click_on_button()
if check_input:
check_input()
示例7: try_cancel_and_close_confirm_modal
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def try_cancel_and_close_confirm_modal(self,
click_on_button,
modal_id,
check_input=None):
close_buttons = ['cancel', 'close']
for close in close_buttons:
click_on_button()
button = self.browser.find_element_by_xpath(
"//div[@id='{id}']"
"//button[contains(@class, '{button}')]".format(
id=modal_id,
button=close))
self.click_through_close(
button, (By.CLASS_NAME, 'modal-backdrop'))
if check_input:
check_input()
示例8: _make
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def _make(self, debug):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.binary_location = settings.SELENIUM_CUSTOM_CHROME_PATH
browser = webdriver.Chrome(settings.SELENIUM_CHROMEDRIVER_PATH, options=options)
browser.get('file://' + os.path.abspath(os.path.join(self.dir, 'input.html')))
self.log = self.get_log(browser)
try:
WebDriverWait(browser, 15).until(EC.presence_of_element_located((By.CLASS_NAME, 'math-loaded')))
except TimeoutException:
logger.error('PDF math rendering timed out')
self.log = self.get_log(browser) + '\nPDF math rendering timed out'
return
response = browser.execute_cdp_cmd('Page.printToPDF', self.template)
self.log = self.get_log(browser)
if not response:
return
with open(os.path.abspath(os.path.join(self.dir, 'output.pdf')), 'wb') as f:
f.write(base64.b64decode(response['data']))
self.success = True
示例9: get_latest_wallpapers
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def get_latest_wallpapers():
browser = webdriver.PhantomJS(PHANTOMJS_PATH, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
today_date = time.strftime("%d+%b+%Y")
yesterday = datetime.now() - timedelta(days=1)
yesterday_date = yesterday.strftime('%d+%b+%Y')
first_page_url = 'http://www.espncricinfo.com/ci/content/image/?datefrom='+yesterday_date+'&dateupto='+today_date+';'
browser.get(first_page_url)
wait = WebDriverWait(browser, 10)
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "img-wrap")))
time.sleep(2)
# let's parse our html
soup = BeautifulSoup(browser.page_source, "html.parser")
images = soup.find_all('div', class_='picture')
for image in images:
url = "http://www.espncricinfo.com/" + image.find('a').get('href')
print(url)
示例10: is_indicator_loaded
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def is_indicator_loaded(browser, chart_index, pane_index, indicator_index, name=""):
# get css selector that has the loading animation for the indicator
elem_loading = find_elements(find_elements(
find_elements(find_elements(browser, 'chart-container', By.CLASS_NAME)[chart_index], 'pane',
By.CLASS_NAME)[pane_index], 'div[data-name="legend-source-item"]', By.CSS_SELECTOR)[
indicator_index], 'div[class^="valuesWrapper"] > span[class^="loader"]', By.CSS_SELECTOR)
# check if any of the elements is loaded
indicator_loaded = True
if len(elem_loading) == 0:
if name != "":
name = "{} at index ".format(name)
log.warn("unable to find 'loading' elements of indicator {}{} on pane {} on chart {}".format(name, indicator_index, pane_index, chart_index))
for elem in elem_loading:
if elem.is_displayed():
indicator_loaded = False
break
return indicator_loaded or len(elem_loading) == 0
示例11: test_login
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def test_login(self):
if self.browser == 'android':
raise unittest.SkipTest("The popup doesn't open in the webview.")
self.get('/')
self.wait_for_element('btn-login', By.CLASS_NAME)
self.click(self.drv.find_elements_by_class_name('btn-login')[-1])
self.sleep()
self.switch_window()
self.wait_for_element('authentication_email', visible=True)
(
self.drv
.find_element_by_id('authentication_email')
.send_keys('test@mockmyid.com', Keys.RETURN)
)
self.switch_window(go_back=True)
self.wait_for_element('UserDropdown', timeout=10)
self.assertIn('Recent Submissions', self.drv.page_source)
示例12: test_recent_submissions
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def test_recent_submissions(self):
self.get('/')
self.wait_for_element(
'tr.submission-row:nth-child(1) > td:nth-child(1)',
by=By.CSS_SELECTOR
)
self.click(self.drv.find_element_by_css_selector(
'tr.submission-row:nth-child(1) > td:nth-child(1)'
))
self.wait_for_element('stat-label', by=By.CLASS_NAME)
self.assertGreater(
len(self.drv.find_elements_by_class_name('stat-label')),
0
)
示例13: test_download_json_button
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def test_download_json_button(self):
self.get('/admin/b0816b52-204f-41d4-aaf0-ac6ae2970923')
self.wait_for_element('btn-primary', by=By.CLASS_NAME)
self.click(self.drv.find_element_by_class_name('btn-primary'))
self.click(self.drv.find_element_by_css_selector(
'.open > ul:nth-child(2) > li:nth-child(1) > a:nth-child(1)'
))
self.sleep()
self.switch_window()
self.sleep()
response = BeautifulSoup(self.drv.page_source, 'html.parser')
try:
json_str = response.find('pre').text
except AttributeError:
self.sleep()
response = BeautifulSoup(self.drv.page_source, 'html.parser')
json_str = response.find('pre').text
data = json.loads(json_str)
self.assertEqual(data['total_entries'], 101)
self.assertEqual(data['total_entries'], 101)
self.assertEqual(len(data['submissions']), 101)
示例14: test_submission_details_button
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def test_submission_details_button(self):
self.get('/admin/b0816b52-204f-41d4-aaf0-ac6ae2970923')
self.sleep()
self.wait_for_element(
'#submissions > tbody > tr:nth-of-type(1)',
by=By.CSS_SELECTOR
)
self.click(self.drv.find_element_by_css_selector(
'#submissions > tbody > tr:nth-of-type(1)'
))
self.wait_for_element('response-data', by=By.CLASS_NAME)
self.assertEqual(
self.drv.find_element_by_class_name('response-data').text,
'3'
)
示例15: test_change_language
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import CLASS_NAME [as 别名]
def test_change_language(self):
survey_id = 'c0816b52-204f-41d4-aaf0-ac6ae2970925'
# login as enumerator
self.get('/debug/login/test_enumerator@fixtures.com')
self.sleep()
self.get('/enumerate/{}'.format(survey_id))
self.sleep()
self.wait_for_element('menu', By.CLASS_NAME)
self.click(self.drv.find_element_by_class_name('menu'))
lang = Select(self.drv.find_element_by_class_name('language_select'))
self.assertEqual(len(lang.options), 3)
self.select_by_index(lang, 1)
self.sleep()
title = self.drv.find_element_by_css_selector(
'.content-padded h3').text
self.assertEqual(title, 'ENUMERATOR_ONLY_SINGLE_SURVEY')