元素必须是用户可编辑的才能清除它(Behat) [英] Element must be user-editable in order to clear it (Behat)
问题描述
我使用Behat框架自动化一个网站,在PHPStorm中工作,使最新的chromedriver和硒机jar运行起来:
I am automating a website using the Behat framework, working in PHPStorm, have the latest chromedriver and selenium jar up and running:
网站上的日期字段
例如:
输入类型=日期ng-show =options.editEnabled
I cant seem to interact with standard Date fields across the site e.g: input type="date" ng-show="options.editEnabled"
:
Feature file: Then I select a start date of "01012014"
public function startDate ($date)
{
$this->getElement('startDate')->setValue($date);
}
返回错误
元素状态:元素
我已经使用相同的其他网站使用相同的代码没有问题,任何人都可以编辑有任何想法,或者是一个已知的问题?
I have used the same across dozens of other websites using the same code with no problems, does anyone have any ideas to get around it or is it a known problem?
推荐答案
我假设你使用PHP和Angular不使它成为一个非常标准的日期字段。执行以下操作(Behat 3)在最后一步之前不会抛出任何错误,因为它也不会更改实际值。
I assume you are using PHP and Angular, which doesn't make it a very standard date field. Doing the following (Behat 3) doesn't throw any errors up until the last step, because it doesn't change the actual value either.
/**
* @When /^I select a "(?P<id>.+)" date of "(?P<date>.+)"$/
*
* @param $id
* @param $date
*/
public function startDate($id, $date)
{
$this->getSession()->getPage()->find('css', '#' . $id)->setValue($date);
}
@javascript
Scenario: Test
When I go to "https://docs.angularjs.org/examples/example-date-input-directive/index.html"
And I select a "exampleInput" date of "2013-11-11"
Then I should see "2013-11-11"
看起来组件必须从javascript接收到值,特别是查看这。
It looks like that the component must receive a value from the javascript, especially looking at this.
编辑:
为了做到这一点,你可以使用JS,虽然如果一个熟悉Angular的人可能建议一个更简单的方法:
To do this with JS you can use the following, though if a person familiar with Angular might suggest a simpler approach:
/**
* @When /^I select date of "(?P<date>.+)"$/
*
* @param $date
*/
public function startDate($date)
{
$element = $this->findElement('//*[@id="exampleInput"]');
$script = '
(function(){
var element = document.evaluate(\'' . $element->getXpath() . '\', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var $scope = angular.element(element).scope();
$scope.$apply(function() {
$scope.value = new Date(\'' . $date . '\');
});
})();
';
$this->getSession()->executeScript($script);
}
@javascript
Scenario: Test
When I go to "https://docs.angularjs.org/examples/example-date-input-directive/index.html"
And I select date of "2013-11-11"
Then I should see "2013-11-11"
测试通过,值被更新。
这篇关于元素必须是用户可编辑的才能清除它(Behat)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!