C# Selenium Struggles to Find a Concealed Element coded in Javascript

Can anyone help me locate the element with the tag

<span _ngcontent-c19=""> ACME Nursing </span>
using Xpath or any other method?

I have attempted various ways to use actions in order to moveToElement, as well as other methods, but I am unable to perform the hover and click action. I have also tried using waits, but I keep encountering the same error message regardless of the approach I take:

Below is the snippet of code containing the hidden element I am trying to find:

<acme-role-facility _ngcontent-c2="" class="ng-tns-c2-1" _nghost-c20="">
  <li _ngcontent-c20="" class="header-item show dropdown" ngbdropdown=""><a _ngcontent-c20="" aria-haspopup="true" class="dropdown-toggle dropdown-toggle" href="javascript:void(0)" id="roleFacilityDropdown" ngbdropdowntoggle="" aria-expanded="true"><span _ngcontent-c20="" class="block m-t-xs" id="roleFacilityName"><span _ngcontent-c20="">ACME Nursing - </span></span><span _ngcontent-c20="" class="block"><span _ngcontent-c20="">Nursing Admissions</span><b _ngcontent-c20="" class="caret"></b></span></a>
    <aht-navigation
      _ngcontent-c20="" aria-labelledby="roleFacilityDropdown" ngbdropdownmenu="" _nghost-c19="" class="dropdown-menu show" x-placement="bottom-left" style="top: 52px; left: 0px;">
      <perfect-scrollbar _ngcontent-c19="" class="nav-facility-container">
        <div style="position: static;" class="ps">
          <div class="ps-content">
            <!---->
            <div _ngcontent-c19="" class="animated fadeInDown light ng-star-inserted" style="">
              <!---->
              <ul _ngcontent-c19="" class="nav navbar-nav ng-star-inserted">
                <!---->
                <li _ngcontent-c19="" class="ng-star-inserted">
                  <!---->
                  <!---->
                  <!----><a _ngcontent-c19="" href="javascript:void(0)" class="active parent-menu dropdown-item ng-star-inserted"><span _ngcontent-c19=""> ACME Nursing </span><i _ngcontent-c19="" class="chevronMargin fa fa-chevron-right"></i></a>
                  <!---->
                  <!---->
                  <!---->
                  <!---->
                </li>

                <!-- More li elements with similar structure... -->

              </ul>
            </div>
          </div>
          <!---->
          <div class="ps__rail-x" style="left: 0px; bottom: 0px;">
            <div class="ps__thumb-x" tabindex="0" style="left: 0px; width: 0px;"></div>
          </div>
          <div class="ps__rail-y" style="top: 0px; right: 0px;">
            <div class="ps__thumb-y" tabindex="0" style="top: 0px; height: 0px;"></div>
          </div>
        </div>
      </perfect-scrollbar>
      <!---->
      </aht-navigation>
  </li>
</acme-role-facility>

This is the error message I am receiving:

**Unhandled Exception: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":".//span[starts-with(@id,'ACME Nursing')]"}
  (Session info: chrome=72.0.3626.109)
  (Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementById(String id)
   at OpenQA.Selenium.By.<>c__DisplayClass16_0.<Id>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at AHT.Browser.FacilityRoleSelect() in C:\Users\che7592\Documents\Visual Studio 2017\Projects\AHT\AHT\Program.cs:line 72
   at AHT.Program.Main(String[] args) in C:\Users\che7592\Documents\Visual Studio 2017\Projects\AHT\AHT\Program.cs:line 33**

Answer №1

There is currently no matching element found with the selector

.//span[starts-with(@id,'ACME Nursing')]
.

To locate the element containing the text ACME Nursing, you can use the selector

//span[normalize-space(.)='ACME Nursing']
, where . refers to the text and normalize-space eliminates any unnecessary spaces.

Alternative method:

//span[normalize-space(.)='ACME Nursing' and @_ngcontent-c19]

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

Before the async function, make sure to set the value using React's useState

Exploring the world of react context api for the very first time. Below is my react code utilizing the context api: const [valChanged, setValChanged] = useState(false); async function modalSave() { await setValChanged(true); // STEP 1 await o ...

Testing the Angular/Ionic project through unit tests

I am facing a challenge with my controller code, which appears to be quite simple. Here is a snippet of the controller: timeInOut.controller('timeInOutController', function($scope, $filter, $ionicScrollDelegate){ ... }); However, when at ...

How to make an Ajax "POST" request to the server using jQuery or AngularJS without sending any parameter data

"Execute a 'POST' request to the server by using the code provided below However, the parameter data is not being sent to the server. I have attempted both the jQuery Way and var request = $.ajax({ url: baseUrl, type:'post', da ...

Troubleshooting a config file problem related to prefixes

While exploring discord.js at , I encountered a problem that has me stuck. Index.js const Discord = require('discord.js'); const { prefix, token } = require('./config.json'); const client = new Discord.Client(); client.on('ready& ...

The functionality for navigating the Angular uib-dropdown using the keyboard is currently experiencing issues

I am currently utilizing Angular Bootstrap 2.2.0 in conjunction with Angular 1.5. Despite enabling the keyboard-nav option, I am experiencing issues with keyboard navigation on UIB dropdowns. Below is the snippet of my code: <div class="btn-group" ...

Angular FlexLayout MediaObserver: How to determine the active width using a specific div?

I am currently working on customizing the behavior of fxFlex. The web application I am working on has the capability to function as a standalone version, occupying the full screen of a web browser, as well as being embedded as a web component. It is design ...

The v-for directive is displaying my list in a single row with multiple columns instead of in a single column with multiple rows

Can someone please assist in rendering my list as shown below: A B C The current rendering looks like this: 1: A 2: B 3: C Below is the code snippet: To-Do List: <input type="text" class = "todo" placeholder = "Next Item" v-on:keyup.enter="add ...

Leveraging JavaScript for Triggering an Infinite Loop of 1 GET and 2 POST Requests

I don't have much experience with JavaScript, but I believe this can be achieved. I require the script to perform 3 tasks: Make a GET request to https://example.com/test.php which will return this JSON: [{"user_id":"12345","email":"<a href="/ ...

Utilize information stored in a database to automatically navigate to a different webpage

I am currently working with PHP, HTML, and a mySQL database. Here are my current project requirements: Retreive specific data from the database and output it. Compare this data with predetermined values. If the data falls outside of the specified range, ...

Steps to create a TypeScript function that mimics a JavaScript function

As I look at this javascript code: // find the user User.findOne({ name: req.body.name }, function(err, user) { if (err) throw err; if (!user) { res.json({ success: false, message: 'Authentication failed. User not found.' ...

Looking to streamline your webpack configuration in vue.config.js? Utilize webpack-chain for efficient setup. And, wondering how to leverage the speed-measure-webpack

Below is the setup in my vue-cli3 configuration file: vue.config.js: const path = require('path') const CompressionWebpackPlugin = require('compression-webpack-plugin') const SpeedMeasurePlugin = require("speed-measure-webpack-plugin" ...

Submitting a form automatically in React Native using Redux

Is there a way to automatically submit a Redux Form in React Native based on certain conditions being met? I attempted to do so below, but it resulted in a warning. The documentation provides an example for remote submitting, but it uses HTML form's ...

Determine the specific table entry that was clicked on

Currently, I am working on developing a dynamic table that includes a button in one of its columns, which triggers a bootstrap modal. I'm a bit unsure on how to determine which button was clicked and how to populate the table accordingly. Admittedly, ...

How can we align the top edge of a div to the center of a circle within a separate div in a responsive manner?

I want to create 2 stacked divs: the first div contains a circular image, and the second div contains text. I want the second div to always cover half of the circle, with its upper edge positioned at the center point of the circle. This is my code: .cov ...

Pause and continue scrolling through the page with the push of a button

I have a question about a simple demo. I am looking to prevent scrolling when button1 is clicked, and then resume scrolling when button2 is clicked. Can someone guide me on how to achieve this? Check out the Fiddle here HTML: <input type='button& ...

Looping through elements with Python's Selenium WebDriver능 utilizing a For Loop

Basically, I am trying to extract all information from the 'Others' page on a website starting from the first item to the last. Here is my attempt: I encountered some difficulties due to the unique structure of the website. My goal is to retriev ...

What could be the reason behind the error message "Java heap space exception in Eclipse" appearing while trying to use JavaScript autocomplete?

Whenever I attempt to utilize a JavaScript template on Eclipse, the program always freezes, displaying an error message stating: "Unhandled event loop exception Java heap space." To troubleshoot this issue, I initiated a top command in Ubuntu for both the ...

Upon submitting the form, the dynamic dependent drop-down list fails to offer any available options

Hey there, I've got a form with two drop-down lists: id="dd-1" & id="dd-2". The options in id="dd-2" are generated from the database based on what's selected in id="dd-1"; I'm using onChange=getChildOf(this.value) in id="dd-1" for this ...

Is it possible to use window.print() to print the entire contents of a DIV with both horizontal and vertical scroll bars?

In my code, I have a div that contains both horizontal and vertical scrollers. Whenever I try to print the content inside this div using the window.print() method, it only prints the visible portion of the div. Here is the code snippet that I have attempte ...

Converting a for loop into a fixed-size array?

I am currently developing a backbone application and have been given some sample code by the provider. The code includes a for loop that generates player names as 'player_1', 'player_2', and so on. However, I would like to manually ente ...