本文整理汇总了Python中display.Display.stop_display方法的典型用法代码示例。如果您正苦于以下问题:Python Display.stop_display方法的具体用法?Python Display.stop_display怎么用?Python Display.stop_display使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类display.Display
的用法示例。
在下文中一共展示了Display.stop_display方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Browser
# 需要导入模块: from display import Display [as 别名]
# 或者: from display.Display import stop_display [as 别名]
class Browser(object):
display = None
browser = None
def __init__(self, downloaded_data_dir=None, implicitly_wait_seconds=10, is_visible=False, profile_directory=None):
if not is_visible:
self.display = Display()
self.downloaded_data_dir = downloaded_data_dir
self.start_browser(downloaded_data_dir, implicitly_wait_seconds, profile_directory)
def __enter__(self):
return self
def __exit__(self, type, value, trace):
if type and self.downloaded_data_dir:
try:
save_to = join(self.downloaded_data_dir, 'error_screenshot_' + datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"))
self.browser.save_screenshot(save_to)
except:
pass
self.close()
def start_browser(self, downloaded_data_dir=None, implicitly_wait_seconds=10, profile_directory=None):
profile = webdriver.FirefoxProfile(profile_directory)
if downloaded_data_dir:
'''start browser with profile'''
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", downloaded_data_dir)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/csv,text/csv")
profile.set_preference("browser.download.manager.scanWhenDone", False)
profile.set_preference("browser.download.manager.showAlertOnComplete", True)
profile.set_preference("browser.download.manager.useWindow", False)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
self.browser = webdriver.Firefox(firefox_profile=profile)
self.browser.implicitly_wait(implicitly_wait_seconds)
def get_browser(self):
if self.browser:
return self.browser
raise Exception("browser don't exist")
def close_browser(self):
'''browser.quit() closes the browser & deleted the temp files'''
if self.browser:
try:
self.browser.quit()
except Exception as e:
log.error("error closing browser, reason: " + str(e))
self.browser = None
def close(self):
self.close_browser()
if self.display:
self.display.stop_display()