问题
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).
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 ?
回答1:
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.
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/
And use this to access the Selenium web automation testing site:
http://docs.seleniumhq.org/download/
EDIT:
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();
}
来源:https://stackoverflow.com/questions/15182000/behat-mink-unable-to-simulate-click-on-button-in-footer