我有一个量角器测试,在过去的几个月里一直运行良好但本周不再有效。它不断抛出元素是不可点击的错误。测试在页面上找到一个按钮元素(在页面加载时最初不可见,但会自动滚动到它)并尝试点击它但失败。
我的环境:
node v7.4.0
protractor v5.0.0
Chrome 56.0.2924.87 (64-bit)
chromedriver_2.26
Mac OS X 10.12.3
与我正在测试的网页类似的HTML示例:
<article class="left-nav-content" ui-view="">
<al-embed-flex id="flex-content" ui-view="html">
<div class="settings">
<div ng-if="ENABLED">
<div ng-repeat="group in tree" class="settings-group" ng-if="group.types.length > 0">
<ul>
<li ng-repeat="type in group.types">
<button type="button" ng-click="connect(type)">
<span class="icon-connect"></span>
<span>Connect</span>
</button>
</li>
</ul>
</div>
</div>
</div>
</al-embed-flex>
</article>
我的方法基本上是$('.settings-group li button').click()
。当我运行我的测试时,我可以看到页面加载,然后我可以看到它自动滚动到按钮(找到元素?或点击它?)但是在尝试点击它时立即引发错误:
WebDriverError: unknown error: Element <button type="button" ng-click="connect(type)">...</button> is not clickable at point (1209, 680). Other element would receive the click: <article class="left-nav-content ng-scope" ui-view="">...</article>
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6),platform=Mac OS X 10.12.3 x86_64)
at Object.checkLegacyResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:505:15)
at parseHttpResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:440:13)
at process._tickCallback (internal/process/next_tick.js:103:7)
From: Task: WebElement.click()
at Driver.schedule (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:816:17)
at WebElement.schedule_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:1921:25)
at WebElement.click (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:2002:17)
at actionFn (/usr/local/lib/node_modules/protractor/lib/element.ts:93:34)
at Array.map (native)
at actionResults.getWebElements.then (/usr/local/lib/node_modules/protractor/lib/element.ts:465:67)
at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)
at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)Error
at ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/lib/element.ts:463:23)
at ElementArrayFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.ts:95:21)
at ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.ts:841:14)
at myClickButtonMethod.then.elem (protractor/page/MyPage.js:26:35)
at ManagedPromise.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1366:14)
at TaskQueue.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2970:14)
at TaskQueue.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2953:27)
at asyncRun (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2813:27)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:676:7
at process._tickCallback (internal/process/next_tick.js:103:7
我在过去一个月里根本没有修改过这个测试。我最近为我的项目设置了TypeScript,但这些测试文件尚未转换为.ts。有趣的是,我的其他2名团队成员可以在没有看到我看到的错误的情况下运行此测试,其中一个人的环境几乎与我的相同。
我已经找到了解决这个问题的方法,很多人建议在点击之前明确滚动到元素?但我也看到有人说滚动现在是自动完成的,当我看我的测试运行时看起来就是这种情况。我还有其他几个测试似乎会自动滚动到看不见的元素,它们似乎运行正常。
请帮忙。 TIA。
答案 0 :(得分:0)
如果镀铬窗口尺寸太小,可能会发生这种情况。
您应该在配置文件中设置窗口大小
onPrepare: function() {
browser.manage().window().setSize(1600, 1000);
}
答案 1 :(得分:0)
是的,窗口大小可能是个问题。
如果您的系统中有完整的分辨率。然后去下面。
onPrepare: function() {
browser.manage().window().setSize(1920, 1080);
}
否则坚持标准尺寸1280,1024,以便始终可见所有元素。