Exploring different methods to locate a random ID using XPATH, CSS path, and selector while conducting Selenium c# testing on a CMS tool

Issue: Hey there, I'm currently working on testing a CMS tool with selenium in C#. The problem I'm facing is finding a suitable selector for a small drop-down button due to the random generation of IDs for all selectors. Every time the script runs, the IDs change along with other identifiers in the HTML code generated.

Attempted Solution: I attempted to save the Xpaths of all drop-down buttons on the page into an array and then tried clicking on the element based on its position in the array. However, I was unsuccessful in storing any element Xpath in the array.

Please advise on what steps I can take in this situation. It could potentially involve dealing with a JavaScript-enabled page.

HTML Code Snippet for the Element:

<span class="epi-extraIcon epi-pt-contextMenu epi-iconContextMenu" role="presentation" title="Display menu" data-dojo-attach-point="iconNodeMenu" _dijitmenuuniqname_51_43="1"/>

Answer №1

Recently, I encountered some challenges while using Selenium in C#.

To resolve this issue, I turned to using XPath.

I utilized Firebug on Mozilla Firefox to inspect the necessary elements and retrieve their Xpath.

Afterwards, I employed HtmlAgilityPack nuget to load the page source, select the nodes, and successfully obtain the elements.

Additionally, I made sure to disable JQuery animations on the page to prevent any further complications.

Here is a snippet of my code for node selection:

var document = new HtmlDocument();

            document.LoadHtml(pageSource);

            var htmlLoaded = DocumentParsing(document.DocumentNode.SelectNodes(
                "/html/body/table[2]/tbody/tr/td/table[2]/tbody/tr/td[1]/font[2]/b[1] |" +
                "/html/body/table[2]/tbody/tr/td/table[2]/tbody/tr/td[1]/font[2]/b[2]));

And here is how I disabled JQuery animations:

 try
            {
                var js = DriverService as IJavaScriptExecutor;
                js.ExecuteScript("$.fx.off = !$.fx.off;");

                return true;
            }
            catch (Exception)
            {
                return false;
            }

I hope this solution proves helpful to you.

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

Adjust the color of each list item depending on an array of strings

Within my perspective, I possess a collection of different statuses. <ul> <li>FIRST_STATUS</li> <li>SECOND_STATUS</li> <li>THIRD_STATUS</li> </ul> To continuously update the statuses in my contr ...

What is the best way to access the value of a child element using $event within AngularJS?

Utilizing $event.currentTarget to access the element on ng-click: <div ng-click="eventHandler($event)" class="bg-master m-b-10" id="slider-tooltips" nouislider=""></div> Upon inspecting my controller&apo ...

How to splice or add elements to an array using JavaScript function

Two buttons on my webpage are designed to add arrays to the orderArray. The arrays are then displayed as an HTML table, with each array having a corresponding button to remove it from the table. The removal process is working as intended, but after using . ...

Deciphering JSON strings using JavaScript

Here is a string that I am trying to parse using Json: {\"description\": \"PSY - Gangnam Style (\\uac15\\ub0a8\\uc2a4\\ud0c0\\uc77c) \\n\\u25b6 NOW available on iTunes: h ...

During the execution of my Selenium test, a new private window unexpectedly appeared even though I did not include this action in my test script

While running a Selenium test script on my website, everything was perfect initially without any errors. However, due to malware affecting my browser, I had to reinstall it. After the reinstallation, when I ran the test again, a new private window opened a ...

Discover distinct and recurring elements

Having two sets of JSON data: vm.userListData = [{ "listId": 1, "permission": "READ" }, { "listId": 2, "permission": "WRITE" }, { "listId": 2, "permission": "READ" }, { "listId": 3, ...

What is the method for identifying which input field the user has chosen on a web page retrieved from a server?

I attempted the code below without achieving the desired outcome. Any assistance would be greatly appreciated. UIPasteboard *pb = [UIPasteboard generalPasteboard]; [pb setString:passwordName]; NSString *jScriptString; jScriptString = [NSString string ...

Ways to disregard the more recent dependency of a Nuget package

Encountering an issue with the Nuget package installation due to a dependency on an older version of Unity while a newer version is already in use. The specific package causing the conflict is NServiceBus Unity, which requires an older version of Unity th ...

Converting currency formats in ASP.NET MVC using C#

In my database, I have a field that stores the prices of my products. The data type is money and I would like to format it as follows: 8.20, 10.00, and 100,00.00 Here's the code I'm using: $<%: string.Format("{0:00.00}", price)%> However, ...

Handling Firebase callbacks once the save operation is completed

Currently using AngularFire with Firebase. Unfortunately, still stuck on Angular 1 :-( I'm curious if there's a method to set up a callback function that triggers every time data is successfully saved in the database. I am aware of the option to ...

Can the functionality of two-way data binding be achieved in Angular without utilizing ng-model and ng-bind?

During an interview, I was presented with this question which sparked my curiosity. While I have a foundational understanding of AngularJS and its ability to enable two-way data binding using ng-model and ng-bind, I am interested in exploring alternative ...

Firefox not receiving output from Headless Selenium/Protractor

The tools and environment I am using for my project setup include: Firefox 30 selenium-server-standalone-2.43.1.jar Xvfb Ubuntu Headless Lineman grunt spec-e2e I have successfully executed Xvfb, Firefox, and lineman grunt spec-e2e wi ...

Azure Function (.NET 7, v4) encountering Cross-Origin Resource Sharing problem

I am experiencing a CORS problem with my Azure function written in C# using .NET 7. It is being called from my Angular application. Interestingly, the same function works fine when called from Postman with the same request body as the Angular application. ...

"An error occurs when trying to trigger a .click() event within a list element

There is a list that can contain either plain text or a link. If there is a link present, the entire list element should be clickable. When attempting to execute the following code: if ($('.link').length) { $('li[data-contains-link]' ...

Comparing Ajax methods: Which one reigns supreme?

I am seeking advice on the best approach to handle a series of Ajax insert, update, and delete operations. Which method is more effective? Creating individual methods for each function (e.g., delete_foo, insert_foo, update_foo, delete_bar, insert_bar, ...

Encountered an unhandled promise rejection: TypeError - The Form is undefined in Angular 6 error

Whenever I attempt to call one .ts file from another using .Form, I encounter the following error: Uncaught (in promise): TypeError: this.Form is undefined The file that contains the error has imported the .ts file which I intend to pass values to. ...

Tips for including information in a chart

I'm facing an issue with my current code as it is not functioning properly. Here is the link to the current output: http://jsfiddle.net/4GP2h/50/ ...

Error in Next.js 13 due to Prisma table mapping causing hydration issues

I recently created a basic project in Next.js 13 and encountered a Hydration Error even though my project is not doing much. The code snippet below seems to be the cause of the issue: import { PrismaClient } from "@prisma/client"; export default ...

Failed validation for Angular file upload

I attempted to create a file validator in the front end using Angular. The validator is quite straightforward. I added a function onFileChange(event) to the file input form to extract properties from the uploaded file. I then implemented a filter - only al ...

Incorrect behavior of responsive background images

For the first time, I am working on a school project that requires me to create a responsive website. I am following the "mobile first" approach. On stackoverflow, I came across a helpful way of making background images responsive: background-image: url(. ...