ich die folgende Funktion bin mit:kann nicht beurteilen XPath (Behat/Mink)
/**
* 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();
}
in meinem FeatureContext.php versuchen, mit dem folgende XPath auf eine Schaltfläche klicken (der Behat Schritt ist): Wenn ich klicke auf das Element mit XPath
//html/body/div[4]/div/div/div/div[2]/div[2]/div[4]/div/div/div/div[2]/ol/li/span[4]/a[1]
Firebug mit diesem XPath glücklich ist, aber Behat mir den Fehler geben:
Could not evaluate XPath: "//html/body/div[4]/div/div/div/div[2]/div[2]/div[4]/div/div/div/div[2]/ol/li/span[4]/a[1]"
Was mache ich falsch?
hier ein Beispiel für die Behat auf w3schools ist, versucht, sich auf das klicken "Try it yourself" Button ":
Feature: xpath try on w3schools.com/tags/att_input_src.asp
Scenario: click button on xpath
@javascript
When I go to "/tags/att_input_src.asp"
And I click on the element with xpath "/html/body/div/div[3]/div[6]/div/a[1]"
And I wait 5 seconds
Then I should be on "tags/tryit.asp?filename=tryhtml_input_src"
den gleichen Fehler gibt, XPath nicht beurteilen konnte, die XPath auf Firebug zeigt die richtige Taste ...
Ihr XPath-Ausdruck liefert wahrscheinlich nichts zurück. Könnten Sie uns eine Beispieleingabe geben, mit der Sie arbeiten können? –
der gleiche xpath gab den richtigen Ort zurück, wenn auf Firebug –