本文整理汇总了Python中selenium.common.exceptions.WebDriverException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.WebDriverException方法的具体用法?Python exceptions.WebDriverException怎么用?Python exceptions.WebDriverException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.common.exceptions
的用法示例。
在下文中一共展示了exceptions.WebDriverException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selenium_execute_with_retry
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def selenium_execute_with_retry(self, execute, command, params):
"""Run a single selenium command and retry once.
The retry happens for certain errors that are likely to be resolved
by retrying.
"""
try:
return execute(command, params)
except Exception as e:
if isinstance(e, ALWAYS_RETRY_EXCEPTIONS) or (
isinstance(e, WebDriverException)
and "Other element would receive the click" in str(e)
):
# Retry
self.builtin.log("Retrying {} command".format(command), level="WARN")
time.sleep(2)
return execute(command, params)
else:
raise
示例2: setUp
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def setUp(self):
"""
Start firefox.
"""
super().setUp()
site = Site.objects.get()
site.name = 'testing'
site.domain = self.live_server_url.split('//')[1]
site.save()
options = Options()
options.headless = True
# Ensure we don't attempt to use the new geckodriver method (which
# isn't working for us. I _think_ selenium 2 defaults to old method,
# but just to make sure.
cap = DesiredCapabilities().FIREFOX
cap['marionette'] = False
try:
self.client = webdriver.Firefox(capabilities=cap, firefox_options=options)
except WebDriverException:
time.sleep(1)
self.client = webdriver.Firefox(capabilities=cap, firefox_options=options)
示例3: go_to
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def go_to(self, url, browser_instance=None):
"""Navigates the active browser instance to the provided URL."""
status = True
try:
print_info("Opening url '%s'" % url)
if browser_instance is not None:
browser_instance.get(url)
else:
self.current_browser.get(url)
except WebDriverException as err:
print_error(err)
if "Reached error page" in str(err):
print_error("Unable to Navigate to URL:{}"\
"possibly because of the url is not valid".format(url))
else:
status = False
except Exception, err:
print_error(err)
status = False
print_error("Unable to Navigate to URL:'%s'" % url)
traceback.print_exc()
示例4: click_stubborn
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def click_stubborn(driver, e, xpath):
logging.debug("Starting stubborn clicks")
MAX_ATTEMPT = 6
attempt = 0
while attempt < MAX_ATTEMPT:
try:
for i in range(10):
attempt += 1
e.click()
break
# breaks if no exception happens
break
except StaleElementReferenceException:
a_nice_refresh(driver)
e = wait_for_xpath_presence(driver, xpath)
except WebDriverException:
break
return e
示例5: open_comment_section
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def open_comment_section(browser, logger):
missing_comment_elem_warning = (
"--> Comment Button Not Found!"
"\t~may cause issues with browser windows of smaller widths"
)
comment_elem = browser.find_elements_by_xpath(
"//button/span[@aria-label='Comment']"
)
if len(comment_elem) > 0:
try:
click_element(browser, Settings, comment_elem[0])
except WebDriverException:
logger.warning(missing_comment_elem_warning)
else:
logger.warning(missing_comment_elem_warning)
示例6: getUserData
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def getUserData(
query,
browser,
basequery="return window.__additionalData[Object.keys(window.__additionalData)[0]].data.",
):
try:
data = browser.execute_script(basequery + query)
return data
except WebDriverException:
browser.execute_script("location.reload()")
update_activity(browser, state=None)
data = browser.execute_script(
"return window._sharedData." "entry_data.ProfilePage[0]." + query
)
return data
示例7: get_number_of_posts
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def get_number_of_posts(browser):
"""Get the number of posts from the profile screen"""
try:
num_of_posts = getUserData(
"graphql.user.edge_owner_to_timeline_media.count", browser
)
except WebDriverException:
try:
num_of_posts_txt = browser.find_element_by_xpath(
read_xpath(get_number_of_posts.__name__, "num_of_posts_txt")
).text
except NoSuchElementException:
num_of_posts_txt = browser.find_element_by_xpath(
read_xpath(
get_number_of_posts.__name__, "num_of_posts_txt_no_such_element"
)
).text
num_of_posts_txt = num_of_posts_txt.replace(" ", "")
num_of_posts_txt = num_of_posts_txt.replace(",", "")
num_of_posts = int(num_of_posts_txt)
return num_of_posts
示例8: get_page_title
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def get_page_title(browser, logger):
""" Get the title of the webpage """
# wait for the current page fully load to get the correct page's title
explicit_wait(browser, "PFL", [], logger, 10)
try:
page_title = browser.title
except WebDriverException:
try:
page_title = browser.execute_script("return document.title")
except WebDriverException:
try:
page_title = browser.execute_script(
"return document.getElementsByTagName('title')[0].text"
)
except WebDriverException:
logger.info("Unable to find the title of the page :(")
return None
return page_title
示例9: close_browser
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def close_browser(browser, threaded_session, logger):
with interruption_handler(threaded=threaded_session):
# delete cookies
try:
browser.delete_all_cookies()
except Exception as exc:
if isinstance(exc, WebDriverException):
logger.exception(
"Error occurred while deleting cookies "
"from web browser!\n\t{}".format(str(exc).encode("utf-8"))
)
# close web browser
try:
browser.quit()
except Exception as exc:
if isinstance(exc, WebDriverException):
logger.exception(
"Error occurred while "
"closing web browser!\n\t{}".format(str(exc).encode("utf-8"))
)
示例10: open_comment_section
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def open_comment_section(browser, logger):
missing_comment_elem_warning = (
"--> Comment Button Not Found!"
"\t~may cause issues with browser windows of smaller widths"
)
comment_elem = browser.find_elements_by_xpath(
read_xpath(open_comment_section.__name__, "comment_elem")
)
if len(comment_elem) > 0:
try:
click_element(browser, comment_elem[0])
return True
except WebDriverException:
logger.warning(missing_comment_elem_warning)
else:
logger.warning(missing_comment_elem_warning)
return False
示例11: get_log
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def get_log(self: "SeleniumTestability", log_type: str = "browser") -> BrowserLogsType:
"""
Returns logs determined by ``log_type`` from the current browser. What is returned
depends on desired_capabilities passed to `Open Browser`.
Note: On firefox, the firefox profile has to have `devtools.console.stdout.content` property to be set.
This can be done automatically with `Generate Firefox Profile` and then pass that to `Open Browser`.
This keyword will mostly likely not work with remote seleniun driver!
"""
ret = [] # type: BrowserLogsType
try:
if is_firefox(self.ctx.driver) and log_type == "browser":
ret = self._get_ff_log(self.ctx.driver.service.log_file.name)
else:
ret = self.ctx.driver.get_log(log_type)
except WebDriverException:
if not self.browser_warn_shown:
self.browser_warn_shown = True
self.warn("Current browser does not support fetching logs from the browser with log_type: {}".format(log_type))
return []
if not ret and not self.empty_log_warn_shown:
self.empty_log_warn_shown = True
self.warn("No logs available - you might need to enable loggingPrefs in desired_capabilities")
return ret
示例12: pwn_check
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def pwn_check(self,email):
"""Check for the target's email in public security breaches using HIBP's API.
Parameters:
email The email address to look-up in Have I Been Pwned's breach database
"""
try:
self.browser.get(self.hibp_breach_uri.format(email))
# cookies = browser.get_cookies()
json_text = self.browser.find_element_by_css_selector('pre').get_attribute('innerText')
pwned = json.loads(json_text)
return pwned
except TimeoutException:
click.secho("[!] The connection to HaveIBeenPwned timed out!",fg="red")
return []
except NoSuchElementException:
# This is likely an "all clear" -- no hits in HIBP
return []
except WebDriverException:
return []
示例13: paste_check
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def paste_check(self,email):
"""Check for the target's email in pastes across multiple paste websites. This includes
sites like Slexy, Ghostbin, Pastebin using HIBP's API.
Parameters:
email The email address to look-up in Have I Been Pwned's pastes database
"""
try:
self.browser.get(self.hibp_paste_uri.format(email))
# cookies = browser.get_cookies()
json_text = self.browser.find_element_by_css_selector('pre').get_attribute('innerText')
pastes = json.loads(json_text)
return pastes
except TimeoutException:
click.secho("[!] The connection to HaveIBeenPwned timed out!",fg="red")
return []
except NoSuchElementException:
# This is likely an "all clear" -- no hits in HIBP
return []
except WebDriverException:
return []
示例14: click
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def click(self, *keys, **offset):
try:
if not any(keys) and not self._has_coords(offset):
self.native.click()
else:
@self._scroll_if_needed
def click():
with self._action_with_modifiers(keys, offset) as a:
a.click() if self._has_coords(offset) else a.click(self.native)
click()
except WebDriverException as e:
if (
# Marionette
isinstance(e, ElementClickInterceptedException) or
# Chrome
"Other element would receive the click" in e.msg
):
self._scroll_to_center()
raise
示例15: click_when_loaded
# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import WebDriverException [as 别名]
def click_when_loaded(self, by, value, retries=DEFAULT_RETRY_COUNT):
"""
Helper method to tell the driver to wait until an element is loaded, then click it.
Since clicking on page elements is the most common source of test flakiness in our selenium suite, this
includes some functionality for retrying the click some number of times if specific exceptions are raised.
"""
retries_remaining = retries
wait = self.wait()
while True:
try:
return wait.until(
lambda driver: driver.find_element(by, value)
).click()
except WebDriverException:
if retries_remaining > 0:
retries_remaining -= 1
else:
raise