Protractor - Discovering elements through various attributes

<ul class="menu">
    <li ui-sref-active="active">
        <a class="ng-scope" translate="menu.home" href="#/home">Home</a>
    </li>
    <li ui-sref-active="active">
        <a class="ng-scope" ui-sref="customer.list" translate="menu.customers" href="#/customers">Customers</a>
    </li>
</ul>

To locate the element containing the text "Home" and using another attribute like translate, you can use a combination of methods as shown below:

element(by.css("[translate='menu.home']:contains('Home')")).click();

This way, you are specifying both the translate attribute and the visible text to make the search more accurate.

Answer №1

by.css(".ng-scope input[translate='menu.customers']");

This conceptually means: find the input element with a translate attribute value of menu.customers, located within an element marked with the ng-scope class. However, this particular code snippet will not work as intended, as there is no parent element with the ng-scope class provided in the HTML example. Additionally, the target element you are seeking is actually an a element, not an input.

It seems more likely that you intended to write:

a.ng-scope[translate='menu.customers']

However, it's worth noting that relying heavily on the broad ng-scope class for selection may not be the most robust approach.


Given the sample HTML structure you've shown, here are some specific CSS selectors you could use:

ul.menu > li > a[href*=home]  // Matches elements with href containing "home"
ul.menu > li > a[href$=home]  // Matches elements with href ending in "home"
ul.menu > li > a[translate="menu.home"]  // Selects elements with translate attribute set to "menu.home"
ul.menu > li > a[translate$=home]  // Finds elements where translate contains "home" 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Why aren't the correct error messages being shown when requesting from the network?

Struggling to figure out how to display informative error messages on the client side instead of generic ones? For instance, when attempting to register with an email that is already taken, users should see a message saying "<a href="/cdn-cgi/l/email-pr ...

I am trying to access the serial number data from an array of objects in ReactJS. Can anyone guide me

Is there a way to extract data from an array of objects, such as getting the serial number in ReactJS? In my current code snippet, I have an array called "number" with values [1, 2, 3]. My goal is to retrieve and display these numbers as a string like th ...

The webpage has finished loading, but capybara is still unable to pass the test

During my automation process, I am checking for the completion of document.readyState === 'complete' and also monitoring a local variable known as window.renderComplete (which indicates when the server has finished rendering the page). However, ...

Utilizing Ionic Storage to set default request headers through an HTTP interceptor in an Angular 5 and Ionic 3 application

I'm attempting to assign a token value to all request headers using the new angular 5 HTTP client. Take a look at my code snippet: import {Injectable} from '@angular/core'; import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from ...

Interacting with shadow DOM elements using Selenium's JavaScriptExecutor in Polymer applications

Having trouble accessing the 'shop now' button in the Men's Outerwear section of the website with the given code on Chrome Browser (V51)'s JavaScript console: document.querySelector('shop-app').shadowRoot.querySelector ...

JavaScript - Utilizing appendChild as soon as an element becomes available

I'm encountering an issue with my Chrome Extension where I am unable to detect some of the elements that I need to select within a page. var innerChat = document.querySelector('.chat-list'); My goal is to appendChild to this element, but t ...

Utilize Javascript or Jquery to intercept and handle both GET and POST requests

Is there a method to effectively intercept and capture both GET and POST requests as they are sent from the browser to the server? In my web application, full page refreshes occur after each request is submitted, however, some pages experience delays in r ...

Ensuring that $.each properly processes all deferreds in jQuery

I am currently working with the following jQuery code: myFunc: function(cmd, obj){ var idToExtMap = this.map; var requireRes = this.reqInst; var deferreds = []; var ret = true; $.each(idToExtMap[cmd], function( ...

Alter the border hue of the checkbox and radio button

Is there a way to modify the border color of checkboxes and radio buttons (both circle and rectangle) using CSS? I've attempted several methods with no success. Can someone provide guidance on this? Any advice would be greatly appreciated. Thank you ...

Is it possible to use "/path/{?}" in a path when working with Node.js?

I am new to node.js and I'm working on creating a route that will verify the authorization of all users when the specified endpoint begins with /api. I've learned that an optional value can be indicated using ? like {_id?}, but is it possible to ...

Converting SQL database information into a JSON array

Greetings, I recently followed a tutorial to create a database, which can be found at this link: https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial My goal is to convert my SQL database into a JSON array, similar to the format shown b ...

Guide to horizontally centering the main div with a div positioned to its left

Seeking the most effective method to achieve the following layout: --------------------------|-------------------------- | | | -------- ------------------------- | | | menu | | ...

initiate a POST request using fetch(), where the data sent becomes the key of

Encountered an issue with sending a POST fetch request where the JSON String turns into the Object Key on the receiving end, specifically when using the { "Content-Type": "application/x-www-form-urlencoded" } header. I attempted to use CircularJSON to res ...

Using several .obj models in THREE.js and identifying which object has been clicked

After following this example on how to load .obj Models using three.js, I decided to experiment with loading more than one model. Here is a snippet of the code I used: loader.addEventListener( 'load', function ( event ) { var object = event.con ...

Angular neglects the specified animation timing

I created a sidebar component that relies on the sidebarExpanded state passed through Input(). Despite the correct animation trigger upon input change, the width adjustment happens abruptly. Interestingly, the same animation code works flawlessly in anothe ...

Challenge with the desktop sidebar in a responsive design

Disclaimer: Seeking input on how to address this issue kindly suggest another title for editing Situation I have a responsive design layout for mobile and desktop with different blocks: Mobile | block1 | | block2 | | clientInfos | | eq ...

Is there a way to retrieve a famo.us/angularjs element from the HTML and convert it into a famo.us constructed object within the

Check out this HTML code that includes a famo.us/Angular scrollview object: <fa-scroll-view> content </fa-scroll-view> I am looking to access the scrollview as a famo.us Scrollview object in my controller so I can control it. Thank you in ...

Exploring the integration of video playback within an Angular-Bootstrap modal upon opening

When it comes to loading videos dynamically based on a scope array of resources, I currently have the following setup: this.open = function (size, resource) { var modalInstance = $uibModal.open({ templateUrl: 'playModal.html', ...

Unable to submit form using jQuery is not functioning as expected

I am attempting to trigger a function when the submit button in the form is clicked. My aim is for the page not to refresh, and instead, I want to use AJAX to add the category. The issue arises when I manually include it in the HTML file, everything works ...

swap out a JavaScript function for a fresh function

In our ordering system, there is a hidden function that I cannot access. Interestingly, this function contains a spelling error which causes a grammar issue to appear in a popup when a user interacts with it. Is there any way for me to either modify the t ...