Searching for element failed: {"method":"link text","selector":"Sales Matrix"}. Working with SELENIUM and JAVA using JavascriptExecutor

I have a button that shows collapsible moves when clicked:

https://i.sstatic.net/cTQvg.gif

Here is the information it contains:

<strong data-bind="css: {'admin__collapsible-title': collapsible,
                      title: !collapsible,
                      '_changed': changed,
                      '_loading': loading,
                      '_error': error}" class="admin__collapsible-title">
            <span data-bind="i18n: label">Sales Matrix</span>
            <!-- ko if: collapsible --><span class="admin__page-nav-item-messages">
                <span class="admin__page-nav-item-message _changed">
                    <span class="admin__page-nav-item-message-icon"></span>
                    <span class="admin__page-nav-item-message-tooltip" data-bind="i18n: 'Changes have been made to this section that have not been saved.'">Changes have been made to this section that have not been saved.</span>
                </span>
                <span class="admin__page-nav-item-message _error">
                    <span class="admin__page-nav-item-message-icon"></span>
                    <span class="admin__page-nav-item-message-tooltip" data-bind="i18n: 'This tab contains invalid data. Please resolve this before saving.'">This tab contains invalid data. Please resolve this before saving.</span>
                </span>
                <span class="admin__page-nav-item-message-loader">
                    <span class="spinner">
                       <!-- ko repeat: 8 --><span data-repeat-index="0"></span><span data-repeat-index="1"></span><span data-repeat-index="2"></span><span data-repeat-index="3"></span><span data-repeat-index="4"></span><span data-repeat-index="5"></span><span data-repeat-index="6"></span><span data-repeat-index="7"></span><!-- /ko -->
                    </span>
               </span>
            </span><!-- /ko -->
        </strong>

Despite various attempts, I am unable to click on the button successfully.

My attempts include:

a) driver.findElement(By.xpath("//span[contains(text(),'Sales Matrix')]")).click();. 


b) driver.findElement(By.xpath("//span[normalize-space()='Sales Matrix']")).click();.

I suspect it may be a locator issue and was considering using JavascriptExecutor, but unsure how to proceed in this scenario.

What steps should I take?

Answer №1

Just wanted to note that there are multiple ways to initiate a click action.

// Using Action class
Actions actions = new Actions(browser);
actions.click(tempWebElem).build().perform();

// Using JavaScript Executor
((JavascriptExecutor) driver).executeScript("arguments[0].click();", tempWebElem);

// Using WebElement directly
driver.findElement(tempElem).click();

// Simulating a click using Send Keys
driver.findElement(tempElem).sendKeys(Keys.RETURN);

In our project setup, I have incorporated these functionalities within a nested try-catch block to handle any locator issues gracefully.

Answer №2

My solution to this problem involved the following steps:

WebElement element = driver.findElement(By.xpath("//span[contains(text(),'Sales Matrix')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

Appreciate the help!

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

Analyzing and tallying the size of each filtering element

In my JavaScript code, I have an array called Projects and another one called Teams. const Projects = [{fkTeamId: 'a'}, {fkTeamId: '8'}, {fkTeamId: 'c'}, {fkTeamId: 'a'}]; const Teams = [{TeamId: 'a'}, {Te ...

The React app is encountering a ReferenceError because the variable "e" has not been

I am encountering an issue with my react application where I am unable to display the same icon from skycons multiple times. I came across this post discussing the same problem. However, when I tried implementing the solution provided, I encountered an err ...

How can I prevent an endless loop in jQuery?

Look at the code snippet below: function myFunction(z){ if(z == 1){ $(".cloud").each(function(index, element) { if(!$(this).attr('id')){ $(this).css("left", -20+'%'); $(this).next('a').css ...

Vite is turning a blind eye to compiler errors until the specific file is executed during runtime

There's an odd issue with Vite that allows me to log in to my app and use it freely, until I click on a page that triggers a compilation error. Once that happens, the page won't render and the error is displayed in the console. Strangely enough, ...

What sets apart utilizing .newInstance() from abstaining from it?

When looking at various Java examples that connect to a database, I've noticed that some use the newInstance() method while others do not. Surprisingly, both approaches seem to work just fine. I'm curious as to why there is this discrepancy in us ...

What is the reasoning behind exporting it in this manner in the index file?

As I was going through a tutorial about nests, there was this step where the instructor made a folder named "dtos" and inside it, they created two dto files (create-user.dto and edit-user.dto). Following that, they also added an index file in the same fold ...

Encountered a glitch in Eclipse - Exception java.lang.RuntimeException was thrown while attempting to initialize the Selenium session with

Utilized jdk 7, selenium-server-standalone-2.25.0.jar, eclipse java indigosr1win32. Upon running the server using cmd: java - jar selenium-server-standalone-2.25.0.jar 4444 The server stops on its own after displaying a message and then shows: server n ...

Learn how to interpret incorrectly formatted .txt binary files in MATLAB

I recently developed a Java program that writes numeric data to a binary .txt file, with the intention of processing this data using Matlab. Within the Java program, I utilized DataOutputStream to input float numbers into a 'data.txt' file. To c ...

Corrupted PDF file producing distorted images

I recently created a well-designed HTML page that can be transformed into a PDF format. The HTML page displays correctly in the web browser. https://i.sstatic.net/D0DE8.png However, when I execute window.print(), the structure appears distorted. https:/ ...

The section element cannot be used as a <Route> component. Every child component of <Routes> must be a <Route> component

I recently completed a React course on Udemy and encountered an issue with integrating register and login components into the container class. The course used an older version of react-router-dom, so I decided to upgrade to v6 react router dom. While makin ...

When you create an object with associations in SailsJS, it automatically triggers an update

Currently, I am utilizing Sails version 0.10.5 for my project. In the development process, I have established three models interconnected through associations. These models include a Candidate, an Evaluator, and a Rating; where an evaluator provides rating ...

Generating Dynamic Xpath - A Comprehensive Guide to Creating Customized X

Is there a Way to Generate Dynamic Xpath Efficiently? I) All modules in my project have the same element pattern and location, with only the id changing based on the module name II) The id pattern in my project is as follows: Module-1 driver.findElemen ...

Implementing Node.js to deliver images for HTML canvas

I've been toying around with node.js, attempting to create a basic game to dive deeper into networking concepts. However, I've hit a roadblock and despite scouring the internet for answers, I can't seem to find a solution. Along the way, I d ...

Best practices for securing data when transmitting AJAX requests

I am facing the challenge of escaping text that is being generated via AJAX. If I include a script in the database entry, such as <script>alert('hello world');</script>, it ends up executing a popup on the page. Below is my function ...

Unable to show the same error message in multiple locations using identical code

I am facing an issue where error messages are not displaying for an empty input field, while they work perfectly fine for a textarea. The if statement for the inputName seems to be working, but the else statement is not being triggered. What could be causi ...

JavaScript plugin designed for effortless conversion of JSON data to structured HTML code

I want to add this JSON data to an HTML element. [ { "website":"google", "link":"http://google.com" }, { "website":"facebook", "link":"http://fb.com" } ] Is there an easy way to convert this using a plugin ...

Dynamic SVG circles with timer and progress animation

Is there a way to modify the following: var el = document.getElementById('graph'); // get canvas var options = { percent: el.getAttribute('data-percent') || 25, size: el.getAttribute('data-size') || 220, lineW ...

When transitioning from the accordion format for mobile to the tab layout for desktop, the tab panel displays an inaccurate title despite the content being accurate

Currently, I am working on developing a navigation system. The objective is to have an accordion-like layout for mobile and tab-based layout for desktop. Although I have implemented this setup, there seems to be an issue: For instance, if "Link #2" tab is ...

Issue with reCAPTCHA callback in Firebase Phone Authentication not functioning as expected

I have been working on integrating phone authentication into my NextJS website. I added the reCAPTCHA code within my useEffect, but for some reason, it does not get triggered when the button with the specified id is clicked. Surprisingly, there are no erro ...

The table value is only updated once with the onclick event, but the updated value is not displayed when the event is clicked again

I am facing an issue with updating names in a table through a modal edit form. The first name update works perfectly, but the second update does not reflect in the table. I want every change made in the modal edit form to be instantly displayed in the tabl ...