0

This is my Code (without imports and stuff):

driver.get('http://democaptcha.com/demo-form-eng/hcaptcha.html')
time.sleep(3)
driver.execute_script("document.getElementsByName('h-captcha-response').style.display='none';")

But this throws me the error:

selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot set property 'display' of undefined

when i do:

driver.execute_script("document.getElementById('h-captcha-response-0zu3aawejggj').style.display = 'block';")

it shows me the error

selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read property 'style' of null

(code is referenced to)

Selenium (with python) how to modify an element css style

How can I change/remove style attibute with selenium python?

THANKS!

1
  • getElementsByName returns an array of elements, not one element. You can't do getElementsByName().style. An array has no .style property. Commented May 25, 2021 at 11:08

2 Answers 2

0

It's because it can't find the element. Probably because the ID keeps changing every page load. Another option could be

driver.execute_script("document.querySelector(`[id^='h-captcha-response']`).style.display = 'block'");

It means that it will find the first element with an ID that starts with h-captcha-response.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

driver.execute_script("document.getElementsByName('h-captcha-response')[0].style.display = 'block';")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.