【问题标题】:Ruby Cucumber: Selenium Webdirver - IE 11 link flashes, cannot click onRuby Cucumber:Selenium Webdriver - IE 11 链接闪烁,无法点击
【发布时间】:2017-04-17 12:31:41
【问题描述】:

当我使用 Selenium WebDriver 运行用 Ruby Cucumber 编写的自动化测试时,我遇到了 IE 浏览器链接闪烁的问题。

   Scenario: Navigating to Reporting home page.
      Given I see menu Reporting available.
      When I navigate to "Annual Reporting".
      Then I see the correct header on Annual Reporting page.

home_page.rb(方法一:使用page_object)

     link(:annual_reporting_link, :id => 'annualReportingLinkId')

     def go_to_reporting
       mouse_over_home
       wait_until(5) do
           annual_reporting_link
       end
    end

结果:由于链接闪烁,无法点击链接。

然后我尝试了以下(方法2:使用send_keys)

    @browser.find_element(:id, 'annualReportingLinkId').send_keys :return

    and 

    @browser.find_element(:id, 'annualReportingLinkId').send_keys(KEYS.ENTER)

但它也没有工作。运行测试时出现此错误:

 Selenium::WebDriver::Error::ElementNotVisibleError: Cannot click on element

HTML:

     <div id="homeMenu">
        <ul>
         <li class="has-sub"><a class="homeButton" href="/report-web"></a>
          <ul id="homeLinks">
             <li id="report1LiId"><a href="/report-web/openItems?subApp=report1&amp;rptid=15" id="report1LinkId" class="disabledLinks"><span id="report1LinkName" class="disabledLinksText">Report 1</span></a></li>
             <li id="report2Id"><a href="/report-web/realms?subApp=report2&amp;rptid=16" id="report2LinkId" class="disabledLinks"><span id="report2LinkName" class="disabledLinksText">Report 2</span></a></li>
             <li id="annualLiId"><a href="/report-web?subApp=annual" id="annualReportingLinkId"><span id="annualReportingLinkName">Annual Reporting</span></a></li>
             <li id="administrationLiId"><a href="/report-web/administration?subApp=ADMIN" id="administrationLinkId" class="disabledLinks"><span id="administrationLinkName" class="disabledLinksText">Manage Users</span></a></li>
           </ul>
        </li>
   </ul>
  </div>

测试自动化能够扩展主菜单,其中包含子菜单 - 超链接。但是在 mouse_over_home(主菜单)之后,子菜单开始闪烁。我需要点击“annual_reporting_link”才能进入这个报告页面,但是因为闪烁,测试自动化根本无法点击。

有人有适合您的解决方案吗?请分享您的解决方案。

环境:

   Ruby: 1.9.3
   Cucumber: 2.1.0
   Selenium Webdriver: 2.53.4 
   page-object: 1.2.0
   IE: 11

【问题讨论】:

  • 请发布重现此问题所需的(最少的)selenium-webdriver 代码。
  • 我刚刚用一些代码编辑了我的问题。谢谢!
  • “链接闪烁”是什么意思?这是一个导航菜单,您需要将鼠标悬停在上面才能单击子菜单链接?如果是这样,您如何扩展菜单 - 即mouse_over_home 做什么?
  • 嗨贾斯汀,我刚刚用你的问题更新了我的问题。是的,我需要将鼠标悬停在点击子菜单链接。请让我知道您的想法。谢谢!
  • 嗨,贾斯汀,听起来您可能在使用 Selenium WebDriver 的 IE 浏览器中遇到了同样的问题。你知道是否有任何解决方法吗?谢谢!

标签: ruby internet-explorer selenium-webdriver cucumber page-object-gem


【解决方案1】:

我在使用 Selenium Webdriver 和 IE 之前遇到过这个问题。我发现这是我的 IE 版本和 Selenium Webdriver 之间的错误。

当我遇到这个问题时,我在点击链接之前放了一个断点并调试了测试,然后我手动尝试在 IE 中点击链接,但我仍然无法做到 10 次中有 9 次因为这个错误,链接只是“闪烁”并且没有响应。

我建议将您的 Selenium Webdriver 版本升级到 3.0.0 版本,这样应该可以解决问题。

如果您不想跳转到 Selenium Webdriver 3.0.0,您需要找出您正在使用的 IE 11 的确切版本。尝试升级或降级您的 IE 11 版本,这也应该可以解决问题,但在升级到 Selenium Webdriver 3.0.0 之前,您可能会发现自己卡在 IE 11 版本上。

另一个解决方案是在您的 IE 配置文件中将持久悬停设置为 false,如下所示:

profile = Selenium::WebDriver::IE::Profile.new
profile['enablePersistentHover'] = false

driver = Selenium::WebDriver.for :IE, :profile => profile

【讨论】:

  • 嗨,丹,感谢您的留言。我将 Ruby 升级到 2.3 并将 Selenium Webdriver 升级到 3.0.0 。我的 Gemfile.lock 文件显示 selenium-webdriver (3.0.0) childprocess (~&gt; 0.5) rubyzip (~&gt; 1.0) websocket (~&gt; 1.0) 这些是您拥有的吗?但我仍然收到相同的链接闪烁错误。我错过了什么?谢谢!
  • 你好 fongfong,你有什么版本的 IE 11?谢谢,丹
  • 嗨 Dan,IE 版本是 11.0.9600.18524CO。 (我忘了提到我还将页面对象 gem 升级到 2.0.0 以使用 Selenium Webdriver gem 3.0.0)。谢谢!
  • 嗯.. 升级我的 Selenium Webdriver 和 IE 11 对我有用。看来 IE 有很多关于 selenium webdriver 的错误。我能想到的最后一件事是我在其他地方读到的,是更改您想要禁用持久悬停的 IE。像这样:'caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer caps['enablePersistentHover'] = false driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps)'
  • 对不起,上面的评论格式错误,我无法编辑它,请查看上面原始答案的更新版本:)
猜你喜欢
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-02
  • 1970-01-01
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多