gpt4 book ai didi

xpath - 无法评估 XPath (Behat/Mink)

转载 作者:行者123 更新时间:2023-12-03 15:30:52 29 4
gpt4 key购买 nike

我正在使用以下功能:

    /**
* 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 步骤是):当我单击带有 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 给了我错误:

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]"



我究竟做错了什么?

这是 w3schools 上的 Behat 示例,尝试单击“自己尝试”按钮”:
             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 显示了正确的按钮......

最佳答案

我有同样的问题。看来你需要省略 /html/body .为了我

//div[2]/div/div[2]/div/table/tbody/tr/td[3]

工作正常。

关于xpath - 无法评估 XPath (Behat/Mink),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130765/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com