【问题标题】:How to stop/handle random HTML popup during test execution - Selenium Webdriver如何在测试执行期间停止/处理随机 HTML 弹出窗口 - Selenium Webdriver
【发布时间】:2017-01-02 02:09:14
【问题描述】:

我希望有人能够帮助我解决我的问题。我在网上做了很多研究,还没有找到任何特定的解决方案。

在运行我的测试用例时,我有时会遇到无法在我的脚本中处理的 HTML 弹出窗口。它是非常随机的(完全基于客户在浏览网站时的行为),并且可以在客户旅程中的任何时候弹出。有时它根本不会弹出。只有当它出现时,才会在 DOM 中看到一个条目。

基本上,它是一个实时聊天窗口(准确地说是 LivePerson),向客户建议如果他们愿意,可以有代理帮助他们完成订单。

这是截图:

popup screenshot

当我检查元素时,以下内容在 Firebug 中可用:

<div id="LPMcontainer-1483053256847-0" class="LPMcontainer LPMoverlay" style="margin: -143px 0px 0px -285px; padding: 0px; border-style: solid; border-width: 0px; outline-color: rgb(106, 159, 177); outline-width: 2px; font-style: normal; font-weight: normal; font-variant: normal; list-style: outside none none; letter-spacing: normal; line-height: normal; text-decoration: none; vertical-align: baseline; white-space: normal; word-spacing: normal; background-repeat: repeat-x; background-position: left bottom; background-color: transparent; border-color: transparent; width: 571px; height: 287px; cursor: pointer; display: block; z-index: 107158; position: fixed; top: 50%; bottom: auto; left: 50%; right: auto;">
 <div role="button" tabindex="0"><img src="https://www./content/dam/tcom/apps/live-person/live-person-chat-bundles-top.jpg" id="LPMimage-1483053256849-2" alt="" class="LPMimage" style="margin: 0px; padding: 0px; border-style: none; border-width: 0px; outline-color: rgb(106, 159, 177); outline-width: 2px; font-style: normal; font-weight: normal; font-variant: normal; list-style: outside none none; letter-spacing: normal; line-height: normal; text-decoration: none; vertical-align: baseline; white-space: normal; word-spacing: normal; position: absolute; z-index: 600; left: 0px; top: 0px;">
</div>
 <img src="https://www./content/dam/tcom/apps/live-person/live-person-chat-bottom.jpg" id="LPMcloseButton-1483053256847-1" alt="" class="LPMcloseButton" style="margin: 0px; padding: 0px; border-style: none; border-width: 0px; outline-color: rgb(106, 159, 177); outline-width: 2px; font-style: normal; font-weight: normal; font-variant: normal; list-style: outside none none; letter-spacing: normal; line-height: normal; text-decoration: none; vertical-align: baseline; white-space: normal; word-spacing: normal; position: absolute; cursor: pointer; z-index: 9999; left: 0px; top: 194px;" data-lp-event="close" role="button" tabindex="0">
</div>

它出现在所有浏览器中。

我想通过以下任一方式处理:

  1. 完全停止加载(同样由于随机性)。 或
  2. 在执行脚本时,一旦出现窗口,它就会按下“不,谢谢”按钮(上面代码中的 id="LPMcloseButton-1483053256847-1"),然后继续执行其余步骤。请注意,id 本质上是动态的,即每次都是唯一的。

我们将非常感谢您的帮助。

【问题讨论】:

    标签: selenium


    【解决方案1】:

    它可能不是随机的。我为其编写自动化程序的一些网站也有类似的东西。经过一番调查,我发现对话框总是在 30 秒后弹出......这似乎是随机的,因为当 30 秒时我可以在任何页面上。经过更多调查后,我发现该站点正在查找 cookie,如果未找到,将触发对话框。我发现在对话框关闭之后创建的 cookie 并在脚本开始时创建了它,这样它就不会再打开了。

    我建议您查找为该站点创建的现有 cookie,并查看其中的内容。然后浏览到该站点,等待对话框弹出,然后将其关闭。看看有什么变化...如果 cookie 发生变化或添加了新的 cookie 等,那么在浏览网站之前只需模仿该行为。

    注意:在我的例子中,我不得不故意浏览到域上丢失的页面,例如somesite.com/someerrorpage,在不启动计时器的情况下创建 cookie。然后我只是导航到该站点并继续执行脚本。

    【讨论】:

    • 非常感谢杰夫。这很方便知道。我会尝试你建议的方式。我的直觉告诉我,这可能也适用于我的情况:-)
    【解决方案2】:

    我想说解决这个问题的最简单方法是创建一个 webdriver 包装器,对于您要发送到 webdriver 的每个调用,首先检查对话框是否存在。如果存在,请将其关闭,否则将操作发送到 webdriver。

    【讨论】:

    • 非常感谢您的回复,卢卡斯。如果我可以问,你能提供一个例子。我正在同时学习 Java 和 Selenium,所以你需要多牵我的手 :-)
    • 恐怕我对 Java 没有任何帮助。我只做 Python/Ruby
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    相关资源
    最近更新 更多