Behat/Mink无法模拟页脚中的按钮 [英] Behat/Mink Unable to simulate click on button in footer

查看:57
本文介绍了Behat/Mink无法模拟页脚中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于页脚中的项目,尝试使用然后按"(对于按钮)或然后按"(对链接)正则表达式失败,错误为找不到元素/具有id | link | name的链接." 例如,我在以下公共站点上发现了这种异常:Earthdata.nasa.gov网站(我们的站点尚未激活).屏幕左侧显示反馈"的按钮不可点击(原文如此).

Attempts to use the "Then I press" (for buttons) or "Then I follow" (for links) regex for items in the footer fails with error "element/link with id|link|name was not found.. " As an example I found this anomaly on this public site: earthdata.nasa.gov site (Our site is not yet active). The button that says "feedback" on the left of the screen is not clickable (sic).

我正在对硒2.29.0服务器进行测试.如何扩展Mink,以便它可以定位并点击"链接,例如上面提到的反馈"按钮?

I am running the test against the selenium 2.29.0 server. How do I extend Mink so that it can locate and "click" on a link such as the "Feedback" button mentioned above ?

推荐答案

您可以使用XPath来单击链接,而不是使用id来单击链接. XPath是在DOM中标识对象的通用方法,因此它将始终有效.

Rather than using the id to click the link, you can use XPath to click the link. XPath is a universal way of identifying objects within the DOM, so it'll always work.

对于那些尚未使用Behat的用户,请使用此链接阅读更多内容.基本上,它是Selenium工具的包装.

For those who have who haven't used Behat, use this link to read more. It's basically a wrapper around Selenium's tools.

http://mink.behat.org/

并使用它来访问Selenium Web自动化测试站点:

And use this to access the Selenium web automation testing site:

http://docs.seleniumhq.org/download/

Ian:感谢MacGyver的指针,这里是解决方案:

Ian: Thanks to MacGyver's Pointer HERE IS THE Solution:

/** Click on the element with the provided xpath query
 *
 * @When /^I click on the element with xpath "([^"]*)"$/
 */
public function iClickOnTheElementWithXPath($xpath)
{
    $session = $this->getSession(); // get the mink session
    $element = $session->getPage()->find(
        'xpath',
        $session->getSelectorsHandler()->selectorToXpath('xpath', $xpath)
    ); // runs the actual query and returns the element

    // errors must not pass silently
    if (null === $element) {
        throw new \InvalidArgumentException(sprintf('Could not evaluate XPath: "%s"', $xpath));
    }

    // ok, let's click on it
    $element->click();

}

这篇关于Behat/Mink无法模拟页脚中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆