与div内部链接的量角器'ElementNotVisibleError' [英] protractor 'ElementNotVisibleError' on link with div inside

查看:80
本文介绍了与div内部链接的量角器'ElementNotVisibleError'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AngularJS 1.2.2并且我正在尝试使用量角器(版本:2.1.0)通过它的ID使用以下规范单击链接;

I'm using AngularJS 1.2.2 and I'm trying to use protractor (version: 2.1.0) to click on a link by it's ID with the following spec;

  it 'allows adding levels', ->
    element(By.id("add_level")).click()

如果我使用以下测试我得到一个错误

If I use the test with the following I get an error

<a id="add_level" ng-click="add_level()"><div class="secondary_btn">Add Level</div></a>

错误:

     ElementNotVisibleError: element not visible
  (Session info: chrome=41.0.2272.89)
  (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Linux 3.16.0-0.bpo.4-amd64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 14 milliseconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'ltsp', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.16.0-0.bpo.4-amd64', java.version: '1.7.0_65'
Session ID: f89f610e73e47854057e98c324a71e38
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.com.google.Chrome.sOTsvG}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=41.0.2272.89, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]

但是如果我不使用内部div那么它工作正常,除了我的样式。

However if I don't use an internal div then it works fine, except I loose my styling.

<a id="add_level" ng-click="add_level()">Add Level</a>

更新

我找到了一个好的工作,通过将id移动到内部div然后我的测试将起作用。

I've found a good work around, by moving the id to the inside div then my tests will work.

<a ng-click="add_level()"><div id="add_level" class="secondary_btn">Add Level</div></a>


推荐答案

您始终可以按文字找到按钮:

You can always locate the button by text:

element(by.xpath("//*[. = 'Add level']")).click();

或者,如果是链接:

element(by.linkText("Add level")).click();

这篇关于与div内部链接的量角器'ElementNotVisibleError'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆