How can one use C# and Selenium to send text to a hidden textarea with the attribute style="display: none;"?

I'm encountering an issue where I am unable to write in the textarea using the sendkeys function in Selenium. The specific textarea I am trying to target has an ID of 'txtSkillsTaught-Value' and is located after a script tag that seems to be hiding its visibility.

I have attempted to use the following code:

driver.findElement(By.Id("txtSkillsTaught-Value")).sendkeys("text");
I also tried switching to the iframe above, but unfortunately, that did not work. I have included an image of the HTML code for reference.

Thank you, Ameyhttps://i.stack.imgur.com/y6ee4.png

Answer №1

On one hand, hiding text that is not visible may not be a good idea. However, there are times when I find it necessary to manipulate elements in this way. Typically, I adjust the visibility of the element before inputting text with a JavaScript execution in my Selenium code (I use Java, but the process should be similar for C#):

executeScript("$('.yui-button.yui-link-button').find(\"textarea[id='txtSkillsTaught-Value']\").css({'opacity':'1', 'visibility':'visible', 'display':'block', 'position':'relative', 'transform':'none'})");
driver.findElement(By.Id("txtSkillsTaught-Value")).sendKeys("text");

This method usually does the trick.

Answer №2

Upon reviewing the HTML code you provided, it appears that the <textarea> element is located outside of the <iframe> with the attribute style="display: none;". In order to input a character sequence into the <textarea>, you can apply the following solution:

IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//td[@class='t-editable-area']//textarea[@class='t-content t-raw-content' and @id='txtSkillsTaught-value']")));
((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].removeAttribute('style')", element);
element.SendKeys("Amey");

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

Learn how to implement Data-driven testing in Selenium using Excel or Numbers on a Mac device!

On my Mac machine, I am utilizing Selenium for testing. However, when it comes to data-driven testing using Excel, how can this be done on a Mac since it doesn't have Excel but uses "Numbers" instead, which is similar? ...

Guide on clicking the SIGN IN button with Selenium and C#

Currently, I am working on creating a test scenario where users will go to a specific URL, input their login details, and then proceed to sign in by clicking a button. Everything is functioning correctly except for the button click action. I have attempted ...

Is it possible to develop a function that can verify various input values and modify their appearance as needed?

I am currently working on creating a form and faced with the challenge of simplifying my code using a function. Specifically, I want to write JavaScript code that will check all input fields in the form to ensure they are filled. If any field is left emp ...

Unable to load the type [ProjectName].WebAPIApplication in the Web API application

I am currently working on a .Net Web Application that utilizes the Web.API Project Properties indicating it is built with .Net 4.5. Within my web page, the code snippet below is used to call one of the methods: $.ajax({ type: 'POST', u ...

Navigate to the same destination with React Router Dom while passing state as a parameter

Let's talk about a scenario with a Link setup like this: <Link to={`/samelocation/${id}`} state={{ state1: 'hello' }}> This link is nested in a sub-component within the main component situated at /samelocation/:id. To ensure that the ...

Tips for utilizing the Selenium Safari Webdriver

Recently, I attempted to utilize Safari WebDriver and meticulously followed the guidelines provided here for constructing a Safari Driver. However, I am now at a loss on how to successfully import and implement it within my code. For this task, I am emplo ...

The DOM is unable to locate the text attribute within a list object, resulting in an AttributeError

I attempted to locate an element within the DOM tree but encountered a problem. Here is my code: age = browser.find_elements_by_xpath("//div[@id='ads']/ul/li[6]/span[2]").text However, I keep getting the error message: AttributeError: 'li ...

Introducing a fresh Backbone object attribute that points to an existing instance property

While working with Backbone/Marionette, I came across something unusual. When I create a new instance of a view with a new collection property and then create another instance of the same view, it seems that the collection property of the second view point ...

Res.redirect() function does not redirect the browser URL as expected when triggered by a request made through a frontend fetch() call

Encountering a new issue that is challenging me. In the backend, there is an API route that redirects the browser URL to /signin using res.redirect('/signin'). Upon this redirection, React Router triggers the rendering of a 'log back in&apos ...

The TypeScriptLab.ts file is generating an error message at line 23, character 28, where it is expecting a comma

I am attempting to convert a ts file to a js file. My goal is to enter some numbers into a textarea, and then calculate the average of those numbers. However, I encountered an error: TypeScriptLab.ts(23,28): error TS1005: ',' expected. I have in ...

Error encountered: Element cannot be clicked on at specified coordinates - Angular/Protractor

Recently, I have been testing out CRUD functionality in an Angular app using Protractor. One recurring issue I've encountered is with the create/edit buttons, which all open the same modal regardless of the page you're on. The frustrating part i ...

Tips for extracting a value from a mongodb aggregate operation

I am attempting to retrieve a value from a MongoDB aggregate in order to display it on an EJS page using the totalAmount variable. The result I am currently receiving is [{"totalAmount":42}] and my goal is to extract only the number, in this case, 42. My ...

What is the best way to eliminate whitespaces and newlines when using "document.execCommand("copy")" function?

I'm currently working on a code that allows users to copy highlighted text without using the keyboard or right-clicking. I also need to remove any extra spaces or line breaks using regex after the text is selected. However, I am facing some issues wit ...

Are none of the page links clickable?

Currently, I am in the process of creating a portfolio website. This is my first attempt at coding HTML and CSS from scratch without the aid of a layout template. I've encountered an issue that has me stumped - the links within the container are not ...

Tips for creating a hierarchical multilevel datatable with JavaScript

I am currently working on implementing a multi-level datatable without relying on any external plugins or libraries. My goal is to achieve this using pure JavaScript, JQuery, or AngularJS. I have explored the following resources: Traverse all the Nodes of ...

I encountered an issue with Array map when attempting to access the data during a dynamic rendering process

function UserTransactionsComponent1() { const [accounts, setAccounts] = useState(); useEffect(() => { async function fetchData() { const res = await fetch( 'https://proton.api.atomicassets.io/atomicassets/v1/accounts' ...

Utilizing Angular for making API requests using double quotes

I am experiencing an issue with my service where the double quotation marks in my API URL are not displayed as they should be. Instead of displaying ".." around my values, it prints out like %22%27 when the API is called. How can I ensure that my ...

Close session when browser/tab is exited

After extensive searching online, I have been unable to find a satisfactory solution for ending a session when a browser or tab is closed without requiring the user to log off. I have attempted numerous JavaScript codes that I came across, but none of the ...

JavaScript: Accessing the selectedIndex of a dropdown list in RadGrid

Currently facing an issue with utilizing the RadGrid control from Telerik. I am attempting to access and manipulate the value of a GridDropDowncolumn within RadGrid using JavaScript (while in edit mode). Does anyone have any suggestions for the correct Ja ...

Presentation for a div's background image with the use of jQuery

My header contains a large div with text contents and boxes, along with a background image. Now I want to create a slideshow for this div's background. Does anyone know how to make a slideshow for a div's background image? I've searched ex ...