Encountered a snag while executing Powershell with Selenium: Error message - unable to interact with

Looking to update a textarea with a value? The script below triggers an error stating "element not interactable". This occurs because the textarea is set to "display:none". However, manually removing the "NONE" word allows the script to successfully set the textarea value.

$browser = Start-SeChrome
$url = "https://www.freepik.com/profile/login"
$browser.Navigate().GoToURL($url)

$CaptchaResponse = "03AGdBq27yHAQ62QjKrtg"
ForEach ($TextArea_Element in (Find-SeElement -Driver $browser -TagName TextArea))
   {
   if ($TextArea_Element.GetAttribute('id') -eq "g-recaptcha-response") {$TextArea_Element.SendKeys($CaptchaResponse)}   
   Break
   }   

In this case, using Javascript seems like the only viable option to directly interact with the DOM (). The approach involves executing commands like:

$browser.executeScript("document.getElementById('g-recaptcha-response').value = $CaptchaResponse")
$browser.executeScript("___grecaptcha_cfg.clients[0].L.L.callback($CaptchaResponse)")

However, this leads to a new issue: javascript error: Invalid or unexpected token.

Answer №1

To run JavaScript with a variable, modify your code like this:

$browser.executeScript("document.getElementById('g-recaptcha-response').value = arguments[0];", $CaptchaResponse)

Just like the first line, extract the variable and substitute it with arguments[0]

$browser.executeScript("___grecaptcha_cfg.clients[0].L.L.callback('arguments[0]');", $CaptchaResponse)

You can pass variables into JavaScript using arguments like this:

$new_style = "display: block; left: 20px;"
$browser.executeScript("arguments[0].style='arguments[1]';", $element, $new_style)

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

A standard procedure for evaluating an application using JavaScript on the client side

I am looking to streamline E2E testing for a web application. The frontend of the app is built on a JavaScript framework, while the backend uses Java technology. While I am aware of the tools and frameworks available for JavaScript testing, I am curious ...

Updating attribute values in a dynamic JSON file with Node.js: A step-by-step guide

My task involves checking if the key in input.json file matches any key in the server.json file, and then updating the value in the server.json file. The challenge lies in the fact that the server.json file is dynamic with an unpredictable structure contai ...

invoking a JavaScript function from an HTML file

I want to create a JavaScript server on Raspbian that not only serves .html content to the browser but also allows for user input through events like button clicks. Both my .html and .js files are located in the same directory, and I have used absolute pat ...

Capturing a res.send(404) error in ExpressJS during production: Tips and tricks

Can middleware handle errors like 404 and 500 when they are returned this way? exports.index = function(req, res) { res.send(404); } In production, I would want to display a custom missing page for these errors. However, my error handler middleware doe ...

NextJS version 14 now throws an error when attempting to use FormData that is

const FormPage = () => { const [categories, setCategories] = useState([]); const [productName, setProductName] = useState(); const [categoryID, setCategoryID] = useState(); const [productDescription, setProductDescription] = useState() ...

When importing a component that is passed as a prop in React, it is causing a blank page to render and is displaying an error in the

Visit this link for the code Everything was running smoothly with the app until I decided to include the Icon component in SidebarOption.js. Now, upon doing so, a blank page appears and an error is displayed in the console: An error occurred stating that ...

Tampermonkey only allows jQuery Click to execute once within a for loop

Attempting to switch the content of a text area to different cars and then trigger a button click to perform an action, repeating this process for each car until all cars have been processed. var index; var cars = ["car1", "car2", "car3"]; var x = documen ...

Leveraging environmental variables in a Vue.js web application

The article I recently came across discussed how to effectively utilize environment variables in vuejs. Following the instructions, I set up my local .env.local file and also installed dotenv. VUE_APP_AUTH_AUTHORITY = 'http://localhost/auth' I ...

Using the Parallax Effect in React

I'm currently working on implementing a parallax effect in React and I've encountered an error that's giving me trouble: Below is the snippet of JavaScript code I have for the parallax effect: export const parallax = document.getElementsBy ...

Python Selenium - Determine the total quantity of items in a dropdown menu

I need help figuring out how to count the number of items in a list box on a webpage and then select multiple items from it. I am able to successfully select the items, but I can't seem to find a way to count them. Here's the code snippet: from ...

Tips for ensuring all images are the same size within a div element

https://i.stack.imgur.com/EkmWq.jpg Is there a way to make sure all the images fit perfectly inside their respective border boxes without appearing stretched? I've tried setting fixed height and width within a div, but they always end up looking off. ...

Create HTML content from a file retrieved from the server

I have been working on a dynamic website project, diving into web development from scratch despite having coding experience in general. As I navigate Angular CLI and Bootstrap, I've come across a fundamental question: Do modern websites house all thei ...

Aggregate X and Y values based on a key in a scatter plot using dc.js

Here is a glimpse of my dataset: var items = [ {name: "X", duration: 1, quantity: 2}, {name: "X", duration: 2, quantity: 1}, {name: "Y", duration: 1, quantity: 4}, {name: "X", duration: 3, quantity: 1 ...

Experiencing difficulty with setting up the ReactJS pagination component

Each time I click on a page number, the maximum size of the pages is returned as a handler parameter (for example, clicking on 2 returns 4). What could be causing this issue? UPDATE class PagingControl extends React.Component{ constructor(props) { ...

Issue: React child components cannot be objects (received: object with keys)

Hey everyone, I could really use some help figuring out what I'm doing wrong. Here is the error message I'm receiving: Error: Objects are not valid as a React child (found: object with keys {id, title, bodyText, icon}). If you meant to render a ...

I am interested in obtaining every separate return value from the reduce() function instead of just the final total

initialValue currentValue position elements final value first calculation 0 1 1 [0, 1, 2, 3, 4] 1 second run 1 2 2 [0, 1, 2, 3, 4] 3 third round 3 3 ...

AngularJS Filter without creating a new object

Within my code, I am dealing with an array of objects that contain sub-objects. This particular array is utilized in an ng-repeat to display data in a table format. To illustrate, consider the following example: device { "name": "computer" ...

ng-options is not compatible with an object as a source

It seems like there should be a simple solution to this issue, but I'm struggling to get ng-options to work with my model object. Essentially, I want to populate my select dropdown with a list of countries. Each option value should be a country code a ...

Leveraging python capabilities within html documents

English is not my first language, so please excuse any spelling errors. I am working on combining HTML and Python to develop a graphical user interface (GUI) that can communicate with a bus system (specifically KNX bus). Currently, I have a Raspberry Pi ...

What could be causing XPath to incorrectly tally the number of substrings?

I am attempting to keep track of how many times an element containing the partial text "25516.B1-" is displayed on the page. Currently, my approach seems flawed as it gives me a count of 17 even though there are only 3 occurrences of this elemen ...