Unable to set or select options using JavaScriptExecutor in C# Selenium

Below is a snippet of HTML code:

<div class="k-list-scroller" unselectable="on" style="height: auto;">
    <ul unselectable="on" class="k-list k-reset" tabindex="-1" aria-hidden="true" id="AdmittedFromId_listbox" aria-live="off" data-role="staticlist" role="listbox">
        <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="0">Physician/Hm w/o HH</li>
        <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="1">Ad Fr Hospital</li>
        <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="2">Ad fr SNF</li>
        <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="3">Admit fr OthFacility</li>
        <li tabindex="-1" role="option" unselectable="on" class="k-item" data-offset-index="4">Ad Court Ordered</li>
    </ul>
</div>

I've made several attempts to interact with the element, without success:

IWebElement admittedFrom = Driver.ngInstance.FindElement(By.XPath("//input[@id='AdmittedFromId']"));
IJavaScriptExecutor admittedFromExecutor = (IJavaScriptExecutor)Driver.ngInstance;
admittedFromExecutor.ExecuteScript("arguments[0].click();", admittedFrom);
admittedFromExecutor.ExecuteScript("document.getElementByID('AdmittedFromId_listbox').data-offset-index='1';");
IWebElement admittedFrom = Driver.ngInstance.FindElement(By.XPath("//input[@id='AdmittedFromId']"));
IJavaScriptExecutor admittedFromExecutor = (IJavaScriptExecutor)Driver.ngInstance;
admittedFromExecutor.ExecuteScript("arguments[0].click();", admittedFrom);
admittedFromExecutor.ExecuteScript("arguments[0].setAttribute('data-offset-index',arguments[1])", admittedFrom, "1");

Despite various attempts, I am unable to successfully modify the value. Any assistance would be greatly appreciated.

Answer №1

It appears that the identifier you are using to locate the element ("AdmittedFromId") does not correspond to the one found in your HTML code ("AdmittedFromId_listbox").

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

An issue encountered with NSwag in TypeScript-Angular involving enum property names and DateTime data type

Encountering issues with generating enums and DateTime attributes using Nswag and OpenApi. First concern is regarding the Enums generation, aiming for a specific format like: export enum BillboardType { BB = 0, BB18 = 1, Direction = 2, Ban ...

How can I link to a different field in a mongoDB Schema without using ObjectID?

I have created two schemas for books and authors: const bookSchema = new mongoose.Schema({ title: String, pages: Number, description: String, author: { type: mongoose.Schema.Types.ObjectId, ref: 'Author' } }); const Book = mongoose.model ...

Tips on creating a slow and gradual border animation that unfolds smoothly

I am looking to create an animation effect on a border, gradually revealing it like in this Codepen example. However, my specific requirements are: The previous line should not be removed, but rather shown along with the new border. The border color ...

MongoDB (Potential number of _id variations)

In the realm of mongoose, there exists a model named Post (defined as var Post = new Schema({...});). Each time a new instance of the Post model is created (var post = new Post({...}); post.save(function (error) {...});), it is assigned a special item kn ...

Retrieving precise information from the backend database by simply clicking a button

As a new full stack programmer, I find myself in a challenging situation. The root of my problem lies in the backend table where data is stored and retrieved in JSON format as an array of objects. My task is to display specific data on my HTML page when a ...

Incorporating Select2 into Your Laravel 4 Application

I've recently incorporated select2 into my multiselect search filter, but I'm struggling to integrate it effectively. Here's the method I'm using: public function getContactByName($name) { return Contact::select(array('id&apo ...

Adjust the HTML 5 range slider to update according to the selected value

Is it possible to create a custom marker on an HTML5 range input element? I'm looking for a way to change the design of the circle marker as it moves along the scale from 1 to 10. Specifically, I want to change the color of the marker based on its po ...

Combine multiple arrays into a single list of tuples

I am curious about how to populate a List<Tuple<double, double>> with arrays. My (brief) code snippet: double[] data1 = new double[5] { 1, 2, 3, 4, 5 }; double[] data2 = new double[5] { 1.5, 1.5, 2.5, 1.2, 1.1 }; List<Tuple<double, dou ...

Utilizing various search and filtering methods with Meteor and Mongodb

I am managing a simple collection with fields for name, last name, category, age, and city. I am looking for an efficient way to perform multiple search and filter operations on these elements within a table. For example, filtering by name and age, age and ...

Tips on automating the click on the prompt "Do you wish to open or save?"

Just curious if there's a way in c# or selenium to handle this scenario: Currently, I'm utilizing selenium to retrieve a file from a web server. However, the popup screen cannot be disabled in IE9. Is there a c# solution for automating clicks ...

Having trouble with prettyphoto functionality

Seeking assistance as I am struggling to get this working Here is how I have set it up: <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen"/ ...

Is the iCheck feature designed to block all parent click events?

I've developed an "interaction tracker" system that collects anonymous data on clicked page elements. By implementing an event listener for clicks on the body, I can track interactions with any element on my site successfully. However, interestingly ...

Nuxt 3: Resolving Issues with Page and Layout Transitions

I've been attempting to incorporate layout transitions into my Nuxt 3 project, but unfortunately, it's not working as expected. I even resorted to replicating the code directly from the Nuxt transition documentation, only to face another failure. ...

Identifying the missing property in a Json object that should be a part of my object using Json.NET

Currently, I am working on deserializing some Json objects using Json.NET. My goal is to create a way to identify if a member in my class is missing from the Json properties for that particular object. For example, consider the following class structure: ...

JavaScript overlay that does not interact with HTML elements directly

Currently, I am facing the challenge of implementing a javascript overlay upon page load without direct access to the html code. My only options are to upload .js and .css files. I have extensively searched for solutions, but as someone with limited exper ...

Ways to update the content of a NodeList

When I execute this code in the console: document.querySelectorAll("a.pointer[title='Average']") It fetches a collection of Averages, each with displayed text on the page: <a class="pointer" title="Average" onclick="showScoretab(this)"> ...

What is the best way to access the CSS font-size property using JavaScript?

I've attempted to adjust the font size using this code: document.getElementById("foo").style.fontSize Unfortunately, this code does not return any results. The CSS styles are all defined within the same document and are not in an external stylesheet ...

Prevent constructor from being obfuscated in .NET

Within .NET, there is an ObfuscationAttribute present. I am struggling to figure out how to keep the code inside a constructor from being obfuscated. // Obfuscated class class MyClass { [Obfuscation(Exclude = true)] // "Attribute 'Obfuscation&apo ...

Having trouble invoking html2canvas within an AngularJS app

When I define html2canvas functions in my controller, the alert in html2canvas doesn't get fired and my canvasToImageSuccess function is not executed. Am I missing something here? In my controller, I have defined html2canvas functions as shown below ...

Upon clicking the button, input numbers into multiple number type inputs

I recently implemented a button in my application that increments the value of input type='number' after it is clicked. While everything seems to be working fine, I noticed that the numbers start from 0 instead of 1. Is there a way for me to ens ...