简体   繁体   English

如何使用没有id或类的量角器测试元素?

[英]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&#x3a;&#x2f;&#x2f;localhost&#x3a;8080&#x2f;web&#x2f;aaaa_customer&#x2f;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.

相关问题 如果元素具有此 id 和 class,如何隐藏它 - How to hide an element if it has this id and class 当元素没有 class 或 ID 时,如何使用 JS 更改元素的样式? - How to change the styling of an element using JS when it has no class or ID? 如果具有类的id元素具有特定CSS属性,如何为它赋予呢? - How to give an element with an id a certain CSS property if it has a class? 如何使用Protractor测试是否加载了正确的图像? - How to use Protractor to test whether the correct image has loaded? 动态生成元素的量角器id - Protractor id of element dynamically generated 隐藏没有类或id的表元素 - Hiding a table element that has no class or id 如果元素具有Id或Class(角),则应用Apply指令 - Apply directive if element has Id or Class (angular) JQuery - 如何测试输入元素是否应用了有效或无效的伪类? - JQuery - How to test if an input element has the valid or invalid pseudo-class applied? Webdriver / Selenium:当元素没有类名,ID或CSS选择器时如何查找? - Webdriver/Selenium: How to find element when it has no class name, id, or css selecector? 如何使用 javascript 使 onclick 动作(向下滚动 150 像素)到没有 id 的特定 class 元素? - How to make onclick action(scroll down 150px) to specific class element that has no id using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM