我正在使用以下功能:
/**
* 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();
}
Run Code Online (Sandbox Code Playgroud)
在我的FeatureContext.php中试图点击一个带有以下XPath的按钮(Behat Step is):当我点击带有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]
Run Code Online (Sandbox Code Playgroud)
Firebug对这个XPath很满意,但是这给了我错误:
无法评估XPath:"// html/body/div [4]/div/div/div/div [2]/div [2]/div [4]/div/div/div/div [2]/ol/LI /跨度[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"
Run Code Online (Sandbox Code Playgroud)
给出相同的错误,无法评估xpath,Firebug上的xpath显示正确的按钮...
小智 6
我有同样的问题.看来你需要省略/html/body.为了我
//div[2]/div/div[2]/div/table/tbody/tr/td[3]
Run Code Online (Sandbox Code Playgroud)
工作良好.
| 归档时间: |
|
| 查看次数: |
3277 次 |
| 最近记录: |