Changing the value of an element using JavaScript through Selenium WebDriver in .NET

I'm attempting to perform a popup page test using the chrome webdriver and selenium2 with .NET, but I am encountering some difficulties. After the window pops up, I need to modify the value of an element. Specifically, I need to change the default value from "selectedIndexes":["1"]" to "selectedIndexes":["0"]"

The element in question is:

<input id="tsTabs_ClientState" name="tsTabs_ClientState" type="hidden" autocomplete="off"
value="{"selectedIndexes":["1"], "logEntries":[], "scrollState":{}}">

My current code is as follows: (Both ExecuteScript lines listed below have been attempted)

Dim chromeDriver = New ChromeDriver("C:\clearcase\Projects\CMS\VbSeTest")
    Try
        'Chrome Test
        chromeDriver.Navigate().GoToUrl("http://localhost/CMS/<location>.aspx")

        Dim queryC As IWebElement = chromeDriver.FindElement(By.Id("ctl00_cphM_grd_ctl00_ctl02_ctl00_ACI_btnInitInsert"))
        queryC.Click()

        Dim current As String = chromeDriver.CurrentWindowHandle
        Dim windows = chromeDriver.WindowHandles.AsEnumerable
        Dim addOrgWindow As IWebDriver
        For Each window In windows
            If window <> current Then
                addOrgWindow = chromeDriver.SwitchTo.Window(window)
            End If
        Next
        'chromeDriver.ExecuteScript("document.getElementById('tsTabs_ClientState').value='{'selectedIndexes':['0'],'logEntries':[],'scrollState':{}}'")
        'OR
        chromeDriver.ExecuteScript("var tab=$get('tsTabs_ClientState'); tab.value ='{'selectedIndexes':['0'],'logEntries':[],'scrollState':{}}'")
        addOrgWindow.FindElement(By.Id("Organization_txtName")).SendKeys("MagicKingdom")
        addOrgWindow.FindElement(By.Id("Organization_cbIndustry_cb_Input")).SendKeys("REP")
        addOrgWindow.FindElement(By.Id("lbAdd")).Click()
        chromeDriver.Quit()

    Catch e As Exception
        chromeDriver.Quit()
        MsgBox(e.ToString())
    End Try

An error keeps occurring at the line: chromeDriver.ExecuteScript(.....

Started ChromeDriver (v2.1) on port 63559

System.InvalidOperationException: unknown error: Runtime.evaluate threw exceptio
n: SyntaxError: Unexpected identifier
(Session info: chrome=28.0.1500.72)
(Driver info: chromedriver=2.1,platform=Windows NT 6.1 SP1 x86_64)
 at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response erro
 rResponse)
 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecu
 te, Dictionary`2 parameters)
 at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptInternal(String script
 , Boolean async, Object[] args)
 at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object
 [] args)
 at VbSeTest.PopUpTest.Main() in C:\clearcase\Projects\CMS\VbSeTest\VbSeTest\P
 opUpTest.vb:line 89
 [8412:6008:0717/103910:ERROR:textfield.h(162)] NOT IMPLEMENTED

Although the javascript executed successfully in Selenium IDE for setting the text field of another hidden client, it does not work here. I have reviewed other Stack answers here, here, or here without success in resolving this issue. Any assistance would be greatly appreciated.

Answer №1

It seems like the issue lies in correctly formatting your JSON string:

chromeDriver.ExecuteScript("var tab=$get('tsTabs_ClientState'); tab.value ='{'selectedIndexes':['0'],'logEntries':[],'scrollState':{}}'")

To resolve this, consider using the following format instead:

chromeDriver.ExecuteScript("var tab=$get('tsTabs_ClientState'); tab.value =\"{'selectedIndexes':['0'],'logEntries':[],'scrollState':{}}\"")

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

The MediaSource API is not supported on Chrome 27

My current browser version is Chrome 27, and based on this source, it is indicated that the MediaSource API comes pre-installed. However, upon further examination on the same page, the test section states that Your browser does not support the MediaSource ...

Utilizing the resource file values in the code-behind: A guide

When working with the XML, I can retrieve values from a resource file by using the corresponding key. First, I include the namespace as shown below: xmlns:res="clr-namespace:WpfApplication3.Properties" Next, I bind the Text using the following method: T ...

ways to interact with a button in Selenium through clicking

When designing a web page, the organization of page number buttons is crucial. Take a look at the code snippet below: <div id="sq-pagination"> <span class="displaying-num">Displaying 31-60 of 281</span> <span> <a class=" ...

Issue Arising During File Transfer in Nativescript

I am currently attempting to upload an image that I captured with Nativescript to a server using a web API that I created in C# (ASP.NET). The API works perfectly fine when tested on Postman, but I encounter an error "Error During Upload" while trying to u ...

The ability to update a variable passed through the state in Link is restricted

Currently, I am in the process of updating the theme in my App using useState. The updated theme is passed to the Topbar Component as a prop, triggering console.log() every time it changes. The theme is then passed from the Topbar to the AboutMe Component ...

`How to implement a dark mode feature in Tailwind CSS with Next.js and styled-jsx`

My website is created using Next.js and Tailwind CSS. I followed the default setup instructions to add them to my project. In order to style links without adding inline classes to each one, I also integrated styled-jsx-plugin-postcss along with styled-jsx ...

Transitioning from fluent NHibernate to using NHibernate mapping by code

There is a relationship where one Country has many States, with each State belonging to only one Country. To map the Country property in StateMap using fluent mapping, it was done as follows: public StateMap() { ... References(m => m.Country).N ...

Steps for triggering Docusign Clickwrap with a button press

My current project involves integrating docusign clickwrap codes. I want the clickwrap to appear when a user clicks a button. However, when I use the code below, the clickwrap opens directly. How can I trigger the ds-click using a button click event? For ...

Arranging elements using the ng-repeat directive in AngularJS

My question pertains to an array I am working with: $scope.answers=["","","",""] This array contains several empty elements. <li ng-repeat="item in answers "><input type="text" ng-model="item"/></li> When running this code, an error i ...

Mastering Tooltip Placement Using CSS or JavaScript

I have been working on creating a CSS-only tooltip for a web application and so far I have managed to create some useful tooltips with different classes: tooltip-up tooltip-down tooltip-left tooltip-right The distinguishing factors between them are t ...

"Executing npm command for launching the Android app results in throwing an

Today is my first day with React and I have just installed node 15 on my Ubuntu OS. I followed the Installation Guide in the documentation which can be found at https://reactnative.dev/docs/getting-started However, when I tried running the command npm -g ...

What is the process of modifying the data in DataTables once it has already been initialized?

I am looking to dynamically populate a table using datatables through an ajax request. Here is the approach I have taken: $(function(e) { $('#CampaignMenu').change(function(e) { $('#ReportWrapper').hide(); ...

Retrieve the specific data from the database when the <tr> element is hovered over

Hey everyone, I've been struggling with a problem for some time now. I have a loop that retrieves values from a database and I want each value to display onmouseover using JavaScript. However, it's only showing the value of the first row for all ...

What steps do I need to follow to execute React/Next code that I have downloaded from GitHub?

I recently obtained a zip file from https://github.com/prgrms-web-devcourse/Team_Price_Offer_FE and extracted its contents. When attempting to launch the program in Visual Studio Code, I inputted the command npm start but encountered an issue. Team_Price_ ...

What is the best way to have text automatically selected upon clicking a category in a combobox? (Vue.JS 2)

I am currently working with a Vue component that looks like this: <script> export default{ template: '\ <select class="form-control" v-model="selected" v-on:change="search">\ <option v- ...

Transfer authorization from one document to another

I am looking for a way to update the contents of a file while maintaining its original permissions intact. Currently, my approach involves reading the file, deleting it, and then creating a new one with the updated content. Here is what I have so far: st ...

What are some ways I can showcase the outcomes of my multiple choice quiz?

I need help with my multiple choice quiz. I want to display the answers under each question and highlight the correct one in bold. Here is the current code: function check() { var question1 = document.quiz.question1.value; var question2 = document.q ...

User-Preferred Dark Mode Toggle Using Material-UI and Fallback Option

I am working on implementing a toggle for "dark mode" that is functioning well. However, I want the initial state to reflect the user's dark/light preference. The problem is that prefersDarkMode seems to be set to false when the page loads. It only c ...

An issue arose with a circular reference during the serialization of a JSON MVC object

I am trying to follow the instructions provided in this video on Youtube. Here is the code in my controller: public ActionResult loaddatacate() { BBDbModel context = new BBDbModel(); context.Configuration.ProxyCreationEnab ...

establish expiration date for image

On my e-commerce site, users upload images to customize product items, such as adding their photo to a cake. I'm curious if there's a way to automatically delete these images after a certain expiry date. Is it possible to implement an automatic ...