[英]How to test an element with protractor that has no id or class?
I am new to protractor and am trying to test various elements within the code (code that I did not write). 我是新的量角器,我正在尝试测试代码中的各种元素(我没写过的代码)。
here is an example of some of the code: 这是一些代码的示例:
<ul class="primary_menu"> <li class=""> <a href="http://localhost:8080/web/aaaa_customer/home" > Home</a> </li>
as can be seen above this element does not have an ID and the class is empty. 从上面可以看出,这个元素没有ID,类是空的。 therefore how do I access this? 因此我如何访问它? below is some code that I wrote to access an element that had an ID: 下面是我为访问具有ID的元素而编写的一些代码:
browser.driver.findElement(by.id('header-search-link')).click();
I have also tried to access an element by.css but it did not work for the problem above. 我也试过访问一个元素by.css但它不适用于上面的问题。
any help would be great 任何帮助都会很棒
If you want to access the Home
link, simply get it by partial link text : 如果要访问“ Home
链接,只需通过部分链接文本获取 :
element(by.partialLinkText('Home'));
Or, you can use a CSS selector : 或者,您可以使用CSS选择器 :
element.all(by.css('ul.primary_menu > li > a')).first();
According to http://angular.github.io/protractor/#/locators#finding-sub-elements you can chain locators to find an element: 根据http://angular.github.io/protractor/#/locators#finding-sub-elements,您可以链接定位器以查找元素:
element(by.css('.primary_menu')).element(by.tagName('li'));
or 要么
element(by.css('.primary_menu li'));
(untested, I never worked with Protractor) (未经测试,我从未使用过量角器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.