• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
夜码人
            管理     

学习marionette_driver package (一)

marionette_driver package

marionette_driver.addons 模块

类marionette_driver.addons.Addons(marionette)

==>用于在 Gecko 运行时安装和检查插件的 API。

这是围绕 Gecko 的 AddonManager API 部分实现的包装器。

使用:

from marionette_driver.addons import Addons
addons = Addons(marionette)//给addons传一个含(marionette)参数的Addons类
addons.install("/path/to/extension.xpi")
-------------------------------------------------------------------------
install()注解:如果插件无需重启,则可以立即使用。否则将需要使用 restart() 重新启动。
install(path, temp=False)
path:要安装的扩展的文件路径
temp:安装一个临时插件。临时插件将在关机时自动卸载并且不需要签名,但它们必须是无需重启的。
return:新安装的插件的插件 ID 字符串
Exception:
marionette_driver.addons.AddonInstallException(message=None, cause=None, stacktrace=None)
插件安装异常

==========================================================================================
from marionette_driver.addons import Addons
addons = Addons(marionette)//给addons传一个含(marionette)参数的Addons类
addons.unstall(addon_id)
---------------------------------------------------------------------------
unstall()----插件卸载
addon_id:要卸载的插件 ID 字符串
注意:如果插件无需重启,它将立即被卸载,否则将需要使用 restart() 重新启动。
如果卸载调用导致 ScriptTimeoutException,则可能传入了无效 ID。
不幸的是,由于 AddonManager 的实现,很难从 Python 检索此错误。

 

marionette_driver.by 模块

类:marionette_driver.by.By

 1 使用
 2 By.属性==>属性值
 3 By.CSS_SELECTOR==>'css选择器'
 4 By.CLASS_NAME==>'class值'
 5 By.ID==>'id值'
 6 By.LINK_TEXT==>'link文本'
 7 By.NAME==>'name值'
 8 By.PARTIAL_LINK_TEXT==>'部分link文本'
 9 By.TAG_NAME==>'标签名称'
10 By.XPAYH==>'XPATH值

注:用法marionette.find_element(By.属性,'属性值')

marionette_driver.date_time_value 模块

类:marionette_driver.date_time_value.DateTimeValue(element)

解释:用于设置 HTML5“日期”和“时间”输入元素值的界面

1 element = marionette.find_element(By.ID, "date-test")
2 dt_value = DateTimeValue(element)
3 dt_value.date = datetime(1998, 6, 2)
4 
5 --注:--
6 data: String型
7 time: String型

marionette_driver.decorators模块

1  marionette_driver.decorators.do_process_check(func)
2 --在函数运行后检查进程状态的装饰器。
3  marionette_driver.decorators.uses_marionette(func)
4 --装饰器,它创建一个Marionette会话,如果不存在则随后将其删除。
5  marionette_driver.decorators.using_context(context)
6 --装饰器,允许函数使用 marionette.using_context 功能在特定范围内执行,并在函数退出后返回旧范围。  :param context: 'chrome' 或 'content'。

marionette_driver.errors 模块

  1 Exception:
  2 marionette_driver.errors.ElementClickInterceptedException(message=None, cause=None, stacktrace=None)
  3 状态:元素点击被拦截
  4 
  5 Exception:
  6 marionette_driver.errors.ElementNotAccessibleException(message=None, cause=None, stacktrace=None)
  7 状态:元素不可访问
  8 
  9 Exception:
 10 marionette_driver.errors.ElementNotInteractableException(message=None, cause=None, stacktrace=None)
 11 状态:元素不可交互
 12 
 13 Exception:
 14 marionette_driver.errors.ElementNotSelectableException(message=None, cause=None, stacktrace=None)
 15 状态:元素不可选择
 16 
 17 Excpetion:(注意:FireFox54后弃用)
 18 marionette_driver.errors.ElementNotVisibleException(message='Element is not currently visible and may not be manipulated', stacktrace=None, cause=None)
 19 状态:元素不可见
 20 
 21 Exception:
 22 marionette_driver.errors.InsecureCertificateException(message=None, cause=None, stacktrace=None)
 23 状态:不安全的证书
 24 
 25 Exception:
 26 marionette_driver.errors.InvalidArgumentException(message=None,
 27 cause=None, stacktrace=None)
 28 状态: 无效参数
 29 
 30 Exception:
 31 marionette_driver.errors.InvalidCookieDomainException(message=None, cause=None, stacktrace=None)
 32 状态:无效的 cookie 域
 33 
 34 Exception:
 35 marionette_driver.errors.InvalidElementCoordinates(message=None, cause=None, stacktrace=None)
 36 状态:无效的元素坐标
 37 
 38 Exception:
 39 marionette_driver.errors.InvalidElementStateException(message=None, cause=None, stacktrace=None)
 40 状态:无效元素状态
 41 
 42 Exception:
 43  marionette_driver.errors.InvalidSelectorException(message=None, cause=None, stacktrace=None)
 44 状态:无效的选择器
 45 
 46 Exception:
 47 marionette_driver.errors.InvalidSessionIdException(message=None, cause=None, stacktrace=None)
 48 状态:无效的会话 ID
 49 
 50 Exception:
 51 marionette_driver.errors.JavascriptException(message=None, cause=None, stacktrace=None)
 52 状态:javascript 错误
 53 
 54 Exception:
 55 marionette_driver.errors.MarionetteException(message=None, cause=None, stacktrace=None)
 56 属性:message---字符串型
 57 状态:网络驱动程序错误,在发生通用不可恢复异常时引发
 58 
 59 Exception:
 60 marionette_driver.errors.MoveTargetOutOfBoundsException(message=None, cause=None, stacktrace=None)
 61 状态:将目标移出边界
 62 
 63 Exception:
 64 marionette_driver.errors.NoAlertPresentException(message=None, cause=None, stacktrace=None)
 65 状态:没有这样的警报(弹窗)
 66 
 67 Exception:
 68 marionette_driver.errors.NoSuchElementException(message=None, cause=None, stacktrace=None)
 69 状态:没有这样的元素
 70 
 71 Exception:
 72 marionette_driver.errors.NoSuchFrameException(message=None, cause=None, stacktrace=None)
 73 状态:没有这样的框架
 74 
 75 Exception:
 76 marionette_driver.errors.NoSuchWindowException(message=None, cause=None, stacktrace=None)
 77 状态:没有这样的窗口
 78 
 79 Exception:
 80 marionette_driver.errors.ScriptTimeoutException(message=None, cause=None, stacktrace=None)
 81 状态:脚本超时
 82 
 83 Exception:
 84 marionette_driver.errors.SessionNotCreatedException(message=None, cause=None, stacktrace=None)
 85 状态:会话未创建
 86 
 87 Exception:
 88 marionette_driver.errors.StaleElementException(message=None, cause=None, stacktrace=None)
 89 状态:过时的元素引用
 90 
 91 Exception:
 92 marionette_driver.errors.TimeoutException(message=None, cause=None, stacktrace=None)
 93 状态:超时
 94 
 95 Exception:
 96 marionette_driver.errors.UnableToSetCookieException(message=None, cause=None, stacktrace=None)
 97 状态:无法设置cookie
 98 
 99 Exception:
100 marionette_driver.errors.UnexpectedAlertOpen(message=None, cause=None, stacktrace=None)
101 状态:意外警报打开
102 
103 Exception:
104 marionette_driver.errors.UnknownCommandException(message=None, cause=None, stacktrace=None)
105 状态:未知的命令
106 
107 Exception:
108 marionette_driver.errors.UnknownException(message=None, cause=None, stacktrace=None)
109 状态:未知错误
110 
111 Exception:
112 marionette_driver.errors.UnknownException(message=None, cause=None, stacktrace=None)
113 状态:无响应的实例异常
114 
115 Exception:
116 marionette_driver.errors.UnsupportedOperationException(message=None, cause=None, stacktrace=None)
117 状态:不受支持的操作
118 
119 Exception:
120 marionette_driver.errors.lookup(identifier)

 

marionette_driver.expected 模块

 1 class:
 2 marionette_driver.expected.element_displayed(*args)
 3 *args: 定位器或网络元素
 4 return:如果元素显示为True,如果隐藏则为False
 5 
 6 意义:检查元素是否可见
 7 可见性意味着元素不仅被显示,而且具有大于0像素的高度和宽度。
 8 Stale elements 意味着已经从当前上下文的 DOM 分离的元素被视为未显示。
 9 这意味着与在 HTMLElement 上调用 is_displayed() 的行为不同。
10 
11 可以通过提供定位器来选择要检查哪个元素的可见性:
12 displayed = Wait(marionette).until(expected.element_displayed(By.ID, "foo"))
13 
14 或者通过提供一个元素:
15 el = marionette.find_element(By.ID, "foo")

 

1 class:
2 marionette_driver.expected.element_enabled(element)
3 element:需要检查的元素
4 return:True为启用,False为未启用
5 意义:检查给定元素是否已启用

 

class:
 marionette_driver.expected.element_not_displayed(*args)
*args:定位器或网络元素
return:隐藏为True,否则为False

定位器用法:
hidden = Wait(marionette).until(expected.element_not_displayed(By.ID, "foo"))
网络元素用法:
el = marionette.find_element(By.ID, "foo")
hidden = Wait(marionette).until(expected.element_not_displayed(el))

 

class:
marionette_driver.expected.element_not_enabled(element)
element:要检查的元素
return:禁用返回True,否则返回False
意义:检查给定的元素是否被禁用

 

class:
marionette_driver.expected.element_not_present(*args)
args:定位器或函数返回 Web 元素
return:如果元素不存在则为真,如果存在则为假
意义:检查当前上下文的 DOM 中是否不存在 Web 元素。

定位器用法:
r = Wait(marionette).until(expected.element_not_present(By.ID, "foo"))
Web元素用法:
r = Wait(marionette).until(
    expected.element_present(lambda m: m.find_element(By.ID, "foo")))

 

1 class:
2 marionette_driver.expected.element_not_selected(element)
3 element: 不被选中的元素
4 return:如果元素未被选中则为真,如果被选中则为假
5 意义:检查是否选择给定元素

 

 1 class: 
 2 marionette_driver.expected.elements_not_present(*args)
 3 *args:定位器或函数返回网络元素列表
 4 return:如果缺少元素则为真,如果存在一个或多个则为假
 5 意义:检查当前上下文的 DOM 中是否不存在 Web 元素。
 6 
 7 
 8 
 9 定位器用法:
10 r = Wait(marionette).until(expected.elements_not_present(By.TAG_NAME, "a"))
11 通过使用函数/lambda 返回一个元素:
12 r = Wait(marionette).until(
13   expected.element_not_present(lambda m: m.find_elements(By.TAG_NAME, "a")))
14 ------------------------------------------------------------------------

 

class: 
marionette_driver.expected.element_present(*args)
*args:定位器或函数返回网络元素列表
return:定位后的 web 元素,或 False
意义:检查当前上下文的 DOM 中是否存在 Web 元素。  这并不一定意味着该元素是可见的。
 
定位器用法:
el = Wait(marionette).until(expected.element_present(By.ID, "foo"))
通过使用函数/lambda 返回一个元素:
el = Wait(marionette).until(
     expected.element_present(lambda m: m.find_element(By.ID, "foo")))

 

 1 class: 
 2 marionette_driver.expected.element_stale(element)
 3 element:要等待的元素
 4 return:如果元素仍然附加到 DOM,则为 False,否则为 True。
 5 
 6 意义:
 7 检查给定元素是否不再附加到当前上下文的 DOM。
 8 这对于等待元素不再存在很有用。
 9 
10 示例用法:
11 el = marionette.find_element(By.ID, "foo")
12 # ...
13 Wait(marionette).until(expected.element_stale(el))

 

1 class:
2 marionette_driver.expected.element_selected(element)
3 element:要选择的元素
4 return:如果元素被选中,则为真,否则为假
5 意义:检查给定元素是否被选中

 

class: 
 2 marionette_driver.expected.elements_present(*args)
 3 *args:定位器或函数返回网络元素列表
 4 return:定位后的 Web 元素列表,或 False
 5 意义:检查当前上下文的 DOM 中是否存在 Web 元素.这并不一定意味着元素是可见的。
 6 
 7 
 8
 9 定位器用法:
10 els = Wait(marionette).until(expected.elements_present(By.TAG_NAME, "a"))
11 通过使用函数/lambda 返回一个元素:
12 els = Wait(marionette).until(
13   expected.element_present(lambda m: m.find_elements(By.TAG_NAME, "a")))
14 ------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 
posted @ 2021-11-03 16:16  夜码人  阅读(152)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3