What is the best way to retrieve values from similar class/properties using Selenium in C#?

Currently, I am in the process of automating tests to compare expected and actual endorsements on a summary page.

I am facing a challenge in reading all the endorsements values displayed on the summary page. The number of endorsements can vary from 2 to 5 depending on the input. I have attempted to use Xpath and CSS selectors, but so far, I have not been successful. Here are the properties of the elements for two endorsements, and the rest of the endorsements will have the same properties, just different values.

My goal is to extract all the endorsements listed on the page so that I can input them into my Excel sheet for comparison against the expected endorsements.

ENDORSEMENT 1:

         <div class="guidance smaller ng-scope" ng-repeat="end in 
          prop.Endorsements">
          <a ng-href="#c03770af-3724-4c3a-a240-e341c0d2c3ef" ng-bind-
          html="end.Name" class="ng-binding" href="#c03770af-3724-4c3a-
          a240-e341c0d2c3ef">Restricted Theft</a>
          </div>
          <a ng-href="#c03770af-3724-4c3a-a240-e341c0d2c3ef" ng-bind-
          html="end.Name" class="ng-binding" href="#c03770af-3724-4c3a-a240-
          e341c0d2c3ef">Restricted Theft</a>

ENDORSEMENT 2:

       <div class="guidance smaller ng-scope" ng-repeat="end in 
       prop.Endorsements">
       <a ng-href="#93ff9067-f64c-4879-933d-8b0a1d077e74" ng-bind-
        html="end.Name" class="ng-binding" href="#93ff9067-f64c-4879-933d-
        8b0a1d077e74">Malicious Damage Exclusion</a>
        </div>
         <a ng-href="#93ff9067-f64c-4879-933d-8b0a1d077e74" ng-bind-
         html="end.Name" class="ng-binding" href="#93ff9067-f64c-4879-933d-
         8b0a1d077e74">Malicious Damage Exclusion</a>

Answer №1

To successfully capture all the anchor elements at once and store them in a list, you'll need a XPath expression.

If you're specifically looking to target only the anchor tags for Endorsements:

IList<IWebElement> listOfEndorsements= Driver.FindElements(By.XPath("//a"));

If there are other types of anchor tags present, you can try the following approach instead:

IList<IWebElement> listOfEndorsements= Driver.FindElements(By.XPath("//div[contains(@ng-repeat,'prop.Endorsements')]/a"));

From there, you can utilize a ForEach loop to extract the necessary information from the list of IWebElements. For example:

foreach (var endorsement in listOfEndorsements)
{
    var text = endorsement.Text;
}

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

Creating unique CSS class and ID names dynamically in PHP

I have two divs with randomly generated IDs and I would like to use those IDs in my CSS instead of using inline styles. Is there a way to achieve this without creating a separate PHP file with a CSS header? For example, I want the padding for the ID $id_ ...

Struggling to manipulate JSON file in C#

Having a library application allows users to register as new users, add books, borrow them, and deposit. However, encountering an issue with the JSON file raises some concerns. The problem arises when trying to manipulate the data using a foreach loop. Odd ...

The vertical tab layout in HTML and CSS is experiencing an issue where the active tab is not being shown above the

Currently, I am developing a web page featuring vertical tabs where each tab corresponds to an image and some content. However, the problem lies in the fact that the active tab is not displaying above the image as expected. In my attempt to resolve this i ...

The logo in the Bootstrap 4 beta navbar-brand does not dynamically resize when the navbar collapses, even with the img

Bootstrap 4 Beta Usage Incorporating a logo and inline menu links in the responsive navbar of my website has been a challenge. While the navbar collapses appropriately with viewport changes, the logo fails to shrink proportionately. This results in the ha ...

Transferring items between containers with stylish animations in AngularJS

Two of my divs have different contents, with one initially empty and the other filled with items. By clicking on an item in the first list, I want to transfer it over to the second list through a visual animation that implies movement from right to left. W ...

Tips for saving individual rows from an HTML table as elements in an ArrayList in Java

I have an array called userNames: ArrayList<String> userNames = new ArrayList<String>(); In a table, there are multiple rows where each row contains a user name as a string value. My goal is to extract all these user names from the table and ...

The Nodejs express static directory is failing to serve certain files

Hello everyone, I'm currently working on a project using NodeJs, Express, and AngularJS. I've encountered an issue where my page is unable to locate certain JavaScript and CSS files in the public static folder, resulting in a 404 error. Strangely ...

Is feature recognition possible in a jQuery plugin?

Can I integrate a tool similar to Modernizr into my plugin? I want to be able to test for specific CSS3 properties without starting from scratch. ...

Adjust the anchor tag content when a div is clicked

I have a list where each item is assigned a unique ID. I have written the HTML structure for a single item as follows: The structure looks like this: <div id='33496'> <div class='event_content'>..... <div>. ...

I am having trouble with clicking the button in Protractor

Here is some HTML code I am working with: <button type="button" ng-click="submitPosition($event, true);navigate($event,'/#/project')" class="btn btn-main" name="submit">CREATE POSITION AND AUTOSOURCE</button> This is a snippet fro ...

CSS animation using a series of linked elements

Is there a way to make my buttons animate sequentially? For example, the second button should start animating only after the first one has finished. Any assistance would be greatly appreciated! a { padding: 6px; display: block; width: 50px ...

Error: The specified capacity was smaller than the current size. Please ensure the required length is sufficient

I'm trying to create a random alphanumeric string with a length between 1K bytes and 2K bytes to save it to a CSV file. However, I encountered an issue: System.ArgumentOutOfRangeException: 'capacity was less than the current size. Parameter na ...

Progress Bar Rating System in Bootstrap 4

Trying to achieve a specific layout using Bootstrap 4: https://i.sstatic.net/Ym6Ov.jpg Disregarding "See All" and "4,327 Ratings" Progress so far has led to: https://i.sstatic.net/hPSRn.png The numerical ratings can be replaced with font icons. Provi ...

Can someone share tips on creating a stylish vertical-loading progress bar with a circular design?

Currently, I am working on developing a unique progress bar that resembles a glass orb filling up with liquid. However, due to its rounded shape, the traditional approach of adjusting the height does not produce the desired result (as illustrated in this f ...

What steps can I take to decrease the padding of this footer?

Is there a way to reduce the height of the footer so it doesn't dominate the screen on both large and small devices? https://i.sstatic.net/nIQz6.png import { Container, Box, Grid } from "@material-ui/core"; const Footer = (props) => { ...

Creating a dynamic word cloud in D3: Learn how to automatically adjust font sizes to prevent overflow and scale words to fit any screen size

I am currently utilizing Jason Davies' d3-cloud.js to create my word cloud, you can view it here 1. I'm encountering an issue where the words run out of space when the initial window size is too small. To address this, I have a function that cal ...

Extra horizontal spacing in CSS

Struggling to eliminate the excess horizontal space on my HTML/CSS page. Any thoughts on what might be causing this? Appreciate any help! ...

Custom Bootstrap 3 Panel Organization

I'm intrigued by the layout shown in the image attached. My attempts to recreate it using a combination of columns and rows have been unsuccessful. Could it be that I'm going about this the wrong way? ...

Strategies for handling elements by class name using Selenium and PHPUnit

I have a situation where I need to target the first element with a specific class name, but there are multiple elements with that class and no unique identifiers. Here is an example of the HTML structure: <table class="default-table"> <t ...

Fade In Effect in Angular 2 Using SwitchCase

Hi everyone, I'm facing an issue with making my switch cases fade in after one is called. Here's what I have so far. When the correct switch case is entered in the input field, I want the current one to fade out and the new one to fade in. How ...