0

I am trying to use python selenium to change the text in a specific JS element. I started out by attempting to simply execute the script using the following:

driver.execute_script("document.querySelector('#cssSelector').textContent='{}'".format(text))

However, unfortunately, this returns null

When looking into the JS the selector is in a specific iframe so I have tried to select the iframe but this has not yet worked:

driver.execute_script('''var element=window.frames['iframe'].document.querySelector("[id='cssselector']"); element.textContent='{}'".format(text))

This code also returns undefined as it cannot find the element.

Is there a better way to do this? thanks

Alex
  • 89
  • 1
  • 10
  • Post your HTML or a link to the page you are automating. It is basically impossible to help you without that information. The first issue I see has to do with your quotations in your `execute_script` block -- wrap the whole script in `"` quotations (`"var element=..."`), and use single quotations like `'` to quote items inside the script such as `'iframe'`. – CEH Jan 20 '20 at 17:38
  • I am looking at Yahoo Recaptcha challenge. Trying to automate some email stuff but just need to input 2captcha token into Recaptcha but it doesn't seem to be working – Alex Jan 20 '20 at 18:16
  • 1
    I don’t think captcha can be automated. That’s why captcha is used to stop bots or any automated tool. – Muzzamil Jan 20 '20 at 18:22
  • the – pcalkins Jan 20 '20 at 20:23
  • I've been looking at this other question [link](https://stackoverflow.com/questions/53688300/2captcha-api-selenium) and it seems to just be using javascript to send the ReCaptcha token – Alex Jan 20 '20 at 23:35

0 Answers0