【发布时间】:2021-05-25 10:57:13
【问题描述】:
这是我的代码(没有导入和其他东西):
driver.get('http://democaptcha.com/demo-form-eng/hcaptcha.html')
time.sleep(3)
driver.execute_script("document.getElementsByName('h-captcha-response').style.display='none';")
但这会给我带来错误:
selenium.common.exceptions.JavascriptException:消息:javascript 错误:无法设置未定义的属性“显示”
当我这样做时:
driver.execute_script("document.getElementById('h-captcha-response-0zu3aawejggj').style.display = 'block';")
它告诉我错误
selenium.common.exceptions.JavascriptException:消息:javascript 错误:无法读取 null 的属性“样式”
(参考代码)
Selenium (with python) how to modify an element css style
How can I change/remove style attibute with selenium python?
谢谢!
【问题讨论】:
-
getElementsByName返回一个元素的array,而不是一个元素。你不能做getElementsByName().style。数组没有.style属性。
标签: javascript python selenium