私は次の機能を使用しています:
/**
* 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();
}
私のFeatureContext.phpで、次のXPathでボタンをクリックしようとしています(Behat Stepは):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 はこの XPath に満足していますが、behat でエラーが発生しています。
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]"
私は何を間違っていますか?
これは、w3schools での Behat の例で、[Try it yourself] ボタンをクリックしようとしています。
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"
同じエラーが発生し、xpath を評価できませんでした。Firebug の xpath には正しいボタンが表示されます...