本文整理汇总了Python中selenium.webdriver.common.by.By.PARTIAL_LINK_TEXT属性的典型用法代码示例。如果您正苦于以下问题:Python By.PARTIAL_LINK_TEXT属性的具体用法?Python By.PARTIAL_LINK_TEXT怎么用?Python By.PARTIAL_LINK_TEXT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类selenium.webdriver.common.by.By
的用法示例。
在下文中一共展示了By.PARTIAL_LINK_TEXT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_bills
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def get_bills(self, output_dir):
logger.info('Looking for download link')
(bills_link, ), = self.wait_and_return(
lambda: self.find_visible_elements_by_descendant_partial_text('BILL & PAYMENT HISTORY', 'h2'))
scrape_lib.retry(lambda: self.click(bills_link), retry_delay=2)
links, = self.wait_and_return(
lambda: self.find_visible_elements(By.PARTIAL_LINK_TEXT, "View Bill PDF")
)
def do_download(link):
scrape_lib.retry(lambda: self.click(link), retry_delay=2)
logger.info('Waiting for download')
download_result, = self.wait_and_return(self.get_downloaded_file)
return self.process_download(download_result, output_dir)
for link in links:
if not do_download(link):
break
示例2: _click_link
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def _click_link(browser, link_text, partial=False):
if partial:
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, link_text)))
element = browser.find_element_by_partial_link_text(link_text)
else:
WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.LINK_TEXT, link_text)))
element = browser.find_element_by_link_text(link_text)
element.click()
示例3: get_documents
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def get_documents(self):
logger.info('Looking for documents link')
documents, = self.wait_and_locate((By.PARTIAL_LINK_TEXT, 'Documents'))
scrape_lib.retry(lambda: self.click(documents), num_tries=3,
retry_delay=5)
self.download_documents()
示例4: partial_link_text
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def partial_link_text(value):
return By.PARTIAL_LINK_TEXT, value
示例5: by_partial_link_text
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def by_partial_link_text(text):
warnings.warn('deprecated; use by.* from selene.support.by', DeprecationWarning)
return (By.PARTIAL_LINK_TEXT, text)
示例6: ensure_element
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def ensure_element(self, locator, selector, state="present", timeout=None):
"""This method allows us to wait till an element appears or disappears in the browser
The webdriver runs in parallel with our scripts, so we must wait for it everytime it
runs javascript. Selenium automatically waits till a page loads when GETing it,
but it doesn't do this when it runs javascript and makes AJAX requests.
So we must explicitly wait in that case.
The 'locator' argument defines what strategy we use to search for the element.
The 'state' argument allows us to chose between waiting for the element to be visible,
clickable, present, or invisible. Presence is more inclusive, but sometimes we want to
know if the element is visible. Careful, its not always intuitive what Selenium considers
to be a visible element. We can also wait for it to be clickable, although this method
is a bit buggy in selenium, an element can be 'clickable' according to selenium and
still fail when we try to click it.
More info at: http://selenium-python.readthedocs.io/waits.html
"""
locators = {'id': By.ID,
'name': By.NAME,
'xpath': By.XPATH,
'link_text': By.LINK_TEXT,
'partial_link_text': By.PARTIAL_LINK_TEXT,
'tag_name': By.TAG_NAME,
'class_name': By.CLASS_NAME,
'css_selector': By.CSS_SELECTOR}
locator = locators[locator]
if not timeout: timeout = self.default_timeout
if state == 'visible':
element = WebDriverWait(self, timeout).until(
EC.visibility_of_element_located((locator, selector))
)
elif state == 'clickable':
element = WebDriverWait(self, timeout).until(
EC.element_to_be_clickable((locator, selector))
)
elif state == 'present':
element = WebDriverWait(self, timeout).until(
EC.presence_of_element_located((locator, selector))
)
elif state == 'invisible':
WebDriverWait(self, timeout).until(
EC.invisibility_of_element_located((locator, selector))
)
element = None
else:
raise ValueError(
"The 'state' argument must be 'visible', 'clickable', 'present' "
"or 'invisible', not '{}'".format(state)
)
# We add this method to our element to provide a more robust click. Chromedriver
# sometimes needs some time before it can click an item, specially if it needs to
# scroll into it first. This method ensures clicks don't fail because of this.
if element:
element.ensure_click = partial(_ensure_click, element)
return element
示例7: get_element
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def get_element(**kwargs):
"""
Judge element positioning way, and returns the element.
"""
if not kwargs:
raise ValueError("Please specify a locator")
if len(kwargs) > 1:
raise ValueError("Please specify only one locator")
by, value = next(iter(kwargs.items()))
try:
LOCATOR_LIST[by]
except KeyError:
raise ValueError("Element positioning of type '{}' is not supported. ".format(by))
if by == "id_":
find_element((By.ID, value))
elem = Seldom.driver.find_elements_by_id(value)
elif by == "name":
find_element((By.NAME, value))
elem = Seldom.driver.find_elements_by_name(value)
elif by == "class_name":
find_element((By.CLASS_NAME, value))
elem = Seldom.driver.find_elements_by_class_name(value)
elif by == "tag":
find_element((By.TAG_NAME, value))
elem = Seldom.driver.find_elements_by_tag_name(value)
elif by == "link_text":
find_element((By.LINK_TEXT, value))
elem = Seldom.driver.find_elements_by_link_text(value)
elif by == "partial_link_text":
find_element((By.PARTIAL_LINK_TEXT, value))
elem = Seldom.driver.find_elements_by_partial_link_text(value)
elif by == "xpath":
find_element((By.XPATH, value))
elem = Seldom.driver.find_elements_by_xpath(value)
elif by == "css":
find_element((By.CSS_SELECTOR, value))
elem = Seldom.driver.find_elements_by_css_selector(value)
else:
raise NameError(
"Please enter the correct targeting elements,'id_/name/class_name/tag/link_text/xpath/css'.")
return elem
示例8: check_eyes_region_by_selector
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import PARTIAL_LINK_TEXT [as 别名]
def check_eyes_region_by_selector(self, selector, value, name, includeEyesLog=False, httpDebugLog=False):
"""
Takes a snapshot of the region of the element found by calling find_element(by, value) from the browser using the web driver
and matches it with the expected output. With a choice from eight selectors, listed below to check by.
Arguments:
| Selector (string) | This will decide what element will be located. The supported selectors include: CSS SELECTOR, XPATH, ID, LINK TEXT, PARTIAL LINK TEXT, NAME, TAG NAME, CLASS NAME. |
| Value (string) | The specific value of the selector. e.g. a CSS SELECTOR value .first.expanded.dropdown |
| Name (string) | Name that will be given to region in Eyes. |
| Include Eyes Log (default=False) | The Eyes logs will not be included by default. To activate, pass 'True' in the variable. |
| HTTP Debug Log (default=False) | The HTTP Debug logs will not be included by default. To activate, pass 'True' in the variable. |
Example:
| *Keywords* | *Parameters* |
| Open Browser | http://www.navinet.net/ | gc | | | | |
| Open Eyes Session | http://www.navinet.net/ | RobotAppEyes_Test | NaviNet_RobotAppEyes_Test | YourApplitoolsKey | 1024 | 768 |
| Check Eyes Region By Selector | CSS SELECTOR | .first.expanded.dropdown | NaviNetCssElement | | | |
| Close Eyes Session | False | | | | | |
"""
if includeEyesLog is True:
logger.set_logger(StdoutLogger())
logger.open_()
if httpDebugLog is True:
httplib.HTTPConnection.debuglevel = 1
searchElement = None
if selector.upper() == 'CSS SELECTOR':
searchElement = By.CSS_SELECTOR
elif selector.upper() == 'XPATH':
searchElement = By.XPATH
elif selector.upper() == 'ID':
searchElement = By.ID
elif selector.upper() == 'LINK TEXT':
searchElement = By.LINK_TEXT
elif selector.upper() == 'PARTIAL LINK TEXT':
searchElement = By.PARTIAL_LINK_TEXT
elif selector.upper() == 'NAME':
searchElement = By.NAME
elif selector.upper() == 'TAG NAME':
searchElement = By.TAG_NAME
elif selector.upper() == 'CLASS NAME':
searchElement = By.CLASS_NAME
else:
raise InvalidElementStateException('Please select a valid selector: CSS SELECTOR, XPATH, ID, LINK TEXT, PARTIAL LINK TEXT, NAME, TAG NAME, CLASS NAME')
eyes.check_region_by_selector(searchElement, value, name)