本文整理汇总了Python中selenium.common.exceptions.InvalidElementStateException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.InvalidElementStateException方法的具体用法?Python exceptions.InvalidElementStateException怎么用?Python exceptions.InvalidElementStateException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.common.exceptions
的用法示例。
在下文中一共展示了exceptions.InvalidElementStateException方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cannot_edit_fail
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import InvalidElementStateException [as 别名]
def cannot_edit_fail(_step):
range_css = 'span.letter-grade'
ranges = world.css_find(range_css)
assert_equal(len(ranges), 2)
assert_not_equal(ranges.last.value, 'Failure')
# try to change the grade range -- this should throw an exception
try:
ranges.last.value = 'Failure'
except (InvalidElementStateException):
pass # We should get this exception on failing to edit the element
# check to be sure that nothing has changed
ranges = world.css_find(range_css)
assert_equal(len(ranges), 2)
assert_not_equal(ranges.last.value, 'Failure')
示例2: check_eyes_region_by_element
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import InvalidElementStateException [as 别名]
def check_eyes_region_by_element(self, selector, value, name, includeEyesLog=False, httpDebugLog=False):
"""
Takes a snapshot of the region of the given selector and element value from the browser using the web driver
and matches it with the expected output. With a choice from four selectors, listed below, to check by.
Arguments:
| Selector (string) | This will decide what element will be located. The supported selectors include: XPATH, ID, CLASS NAME, CSS SELECTOR |
| Value (string) | The specific value of the selector. e.g. an xpath value //*[@id="navbar"]/div/div |
| 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 Element | CLASS NAME | container | NaviNetClassElement | | | |
| 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() == 'XPATH':
searchElement = driver.find_element_by_xpath(value)
elif selector.upper() == 'ID':
searchElement = driver.find_element_by_id(value)
elif selector.upper() == 'CLASS NAME':
searchElement = driver.find_element_by_class_name(value)
elif selector.upper() == 'CSS SELECTOR':
searchElement = driver.find_element_by_css_selector(value)
else:
raise InvalidElementStateException('Please select a valid selector: XPATH, ID, CLASS NAME, CSS SELECTOR')
eyes.check_region_by_element(searchElement, name)
示例3: value
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import InvalidElementStateException [as 别名]
def value(self):
"""
Returns value of the element
:rtype: str
"""
try:
return self.attribute_value('value') or ''
except InvalidElementStateException:
return ''
示例4: comment_image
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import InvalidElementStateException [as 别名]
def comment_image(browser, username, comments, blacklist, logger, logfolder, Settings):
"""Checks if it should comment on the image"""
# check action availability
if quota_supervisor(Settings, "comments") == "jump":
return False, "jumped"
rand_comment = random.choice(comments).format(username)
rand_comment = emoji.demojize(rand_comment)
rand_comment = emoji.emojize(rand_comment, use_aliases=True)
open_comment_section(browser, logger)
comment_input = get_comment_input(browser)
try:
if len(comment_input) > 0:
comment_input[0].clear()
comment_input = get_comment_input(browser)
# below, an extra space is added to force
# the input box to update the reactJS core
comment_to_be_sent = rand_comment + " "
browser.execute_script(
"arguments[0].value = arguments[1];",
comment_input[0],
comment_to_be_sent,
)
# below, it also will remove that extra space added above
# COS '\b' is a backspace char in ASCII
comment_input[0].send_keys("\b")
comment_input = get_comment_input(browser)
comment_input[0].submit()
update_activity(Settings, "comments")
if blacklist["enabled"] is True:
action = "commented"
add_user_to_blacklist(
username, blacklist["campaign"], action, logger, logfolder
)
else:
logger.warning(
"--> Comment Action Likely Failed!" "\t~comment Element was not found"
)
return False, "commenting disabled"
except InvalidElementStateException:
logger.warning(
"--> Comment Action Likely Failed!"
"\t~encountered `InvalidElementStateException` :/"
)
return False, "invalid element state"
logger.info("--> Commented: {}".format(rand_comment.encode("utf-8")))
# get the post-comment delay time to sleep
naply = get_action_delay("comment", Settings)
sleep(naply)
return True, "success"
示例5: check_eyes_region_by_selector
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import InvalidElementStateException [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)