【问题标题】:How Can I Test An Icon Only Visible On Hover?如何测试仅在悬停时可见的图标?
【发布时间】:2013-07-15 04:31:01
【问题描述】:

我有一个页面,用户可以通过单击仅在悬停时可见的铅笔图标来编辑表单的标题。我正在编写一个 phpunit Selenium 测试,我已经尝试过“MoveToElement”和其他一些 Selenium 函数来访问这个不可见的元素,但目前还不支持。

当我尝试直接访问元素时,测试错误和输出

    Element is not currently visible and so may not be interacted with

如何在该图标上模拟悬停的鼠标?

【问题讨论】:

  • 我不确定,我不知道如果它们是……有点菜鸟,我是否会理解如何实现它们

标签: php unit-testing selenium phpunit


【解决方案1】:

最终不得不用 javascript 来做,因为其他 Selenium 方法都没有 php 绑定

$script_show = 'jQuery(".class_name").css("display", "block");';
$script_hide = 'jQuery(".class_name").css("display", "none");';
//prior to accessing the non-visible element
$this->execute( array( 'script' => $script_show , 'args'=>array() ) );
//after it no longer needs to be visible
$this->execute( array( 'script' => $script_hide , 'args'=>array() ) );

【讨论】:

    【解决方案2】:

    当铅笔图标不可见时,您需要移动到/鼠标悬停/悬停/任何元素以使图标可见,然后对铅笔图标执行操作。一旦使铅笔图标可见,您网站的 UI 的实现方式将决定确切的 selenium 代码。

    【讨论】:

    • Hover() 和 mouseover() 还不被 php 支持。使用 moveto() 时,它会出错并输出错误 PHPUnit_Extensions_Selenium2TestCase_Exception: Only move over an element is supported。请传递一个 PHPUnit_Extensions_Selenium2TestCase_Element 实例。当使用 $this->moveto( $this->byXPath( $pencil_xpath ) )
    猜你喜欢
    • 2017-10-19
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2020-03-29
    • 2013-06-18
    相关资源
    最近更新 更多