如何测试仅在悬停时可见的图标?

时间:2013-07-16 20:03:59

标签: php unit-testing selenium phpunit

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

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

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

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

2 个答案:

答案 0 :(得分: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() ) );

答案 1 :(得分:0)

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