元素在点处不可点击 - 量角器

时间:2015-06-16 08:28:20

标签: javascript testing protractor end-to-end

我收到一个错误,我试图点击的元素不是点击,我相信这不是真的。

我的错误看起来:

 1) Open VehiclePage and populate data Populate vehicle data
  Message:
    UnknownError: unknown error: Element is not clickable at point (1315, 371). Other element would receive the click: <div class="form-con
rol combo-options ng-scope ng-animate ng-leave ng-leave-active" ng-if="comboBox.visible" on-click-outside="comboBox.hide">...</div>
 (Session info: chrome=39.0.2171.71)
 (Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c29),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server
did not provide any stacktrace information)
ommand duration or timeout: 30 milliseconds

我的部分代码:

it('Populate vehicle data', function() {
        browser.waitForAngular();
        element(by.css('div#datepicking i.glyphicon-calendar')).click();
        element(by.css('div#datepicking button[ng-click="select(\'today\')"]')).click();
        element(by.model('case.vehicle.adminData.paintColour')).sendKeys(browser.params.paintColour);       
        element(by.xpath('(//*[@id="form-mileage"])')).sendKeys(browser.params.mileage);                        
        element(by.id('form-mileage-unit')).click().then(function() {
            element(by.cssContainingText('option', browser.params.lengthUnit)).click();         
        });;
        element(by.xpath('(//*[@id="form-residual"])')).sendKeys(browser.params.technicalValue);    
        element(by.id('form-vehicle-condition')).click().then(function() {
            element(by.cssContainingText('option', browser.params.vehicleCondition)).click();
        });;    
        element(by.xpath('(//*[@id="form-engine-type"])')).click().then(function() {
            element(by.cssContainingText('option', browser.params.motorType)).click();
        });;

该部分的HTML如下所示:

<div class="col-md-6">
                <div>
                    <div class="form-group">
                        <label for="form-residual" ng-class="{red: !form.residual.$valid}" translate="case.vehicle.adminData.residualValuePercentage" class="ng-scope">Technická hodnota</label>
                           <span popover="Technická hodnota musí být v rozsahu 0-100%" popover-trigger="mouseenter" class="glyphicon glyphicon-question-sign red ng-hide" ng-show="form.residual.$invalid"></span>
                        <div class="input-group">
                            <input type="number" id="form-residual" ng-model="case.vehicle.adminData.residualValuePercentage" name="residual" class="form-control ng-pristine ng-untouched ng-valid ng-valid-min ng-valid-max" max="100" min="0">
                            <span class="input-group-addon">%</span>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="form-group">
                        <label for="form-vehicle-condition" translate="case.vehicle.adminData.vehicleCondition" class="ng-scope">Stav vozu</label>
                        <select type="text" id="form-vehicle-condition" ng-model="case.vehicle.adminData.vehicleCondition" name="vehicleCondition" class="form-control ng-pristine ng-valid ng-touched" ng-options="opt.value as opt.label | translate for opt in options.vehicleCondition"><option value="" class=""></option><option value="0" label="Lepší">Lepší</option><option value="1" label="Odpovídající">Odpovídající</option><option value="2" label="Horší">Horší</option><option value="3" label="Není znám">Není znám</option></select>
                    </div>
                </div>
            </div>

在尝试点击元素(by.id(&#39; form-vehicle-condition&#39;)时总会出现错误。 是否有人可以帮助我找到解决方法?

2 个答案:

答案 0 :(得分:10)

当您尝试单击vehicle-condition元素时,错误消息中的组合框仍然打开 - 很可能是由于其关闭/淡出动画。 您可以尝试停用测试globallylocallywait的动画,以使重叠元素消失:

var EC = protractor.ExpectedConditions;
var element = element(by.id('form-vehicle-condition'));
var isClickable = EC.elementToBeClickable(element);
browser.wait(isClickable, 5000);
element.click();

答案 1 :(得分:8)

我尝试了很多方法, 只有

browser.executeScript('arguments[0].click();', element.getWebElement()); 

适合我。