Javascript python webdriver运行执行脚本错误:无法读取属性';风格';未定义的

Javascript python webdriver运行执行脚本错误:无法读取属性';风格';未定义的,javascript,python,selenium,webdriver,Javascript,Python,Selenium,Webdriver,我正在使用selenium python绑定进行一些基本的浏览器测试。我需要单击一个默认不可见的元素。因此,我希望使不可见元素可见,我尝试使用execute_script()monthod通过使用以下代码使其可见。但是JS代码document.getElementsByCassName(“bdpfmenu”)[0].style.display=“block”在控制台中成功运行,但在使用python时会出现错误消息 js = 'document.getElementsByClassName("bd

我正在使用selenium python绑定进行一些基本的浏览器测试。我需要单击一个默认不可见的元素。因此,我希望使不可见元素可见,我尝试使用
execute_script()
monthod通过使用以下代码使其可见。但是JS代码
document.getElementsByCassName(“bdpfmenu”)[0].style.display=“block”在控制台中成功运行,但在使用python时会出现错误消息

js = 'document.getElementsByClassName("bdpfmenu")[0].style.display="block";'
driver.execute_script(js)
以及错误消息:

selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'style' of undefined

您可以获取样式属性并进行比较

document.getElementsByClassName("bdpfmenu")[0].getAttribute("style")

共享相同的
HTML
。可能有多个元素的类名为“bdpfmenu”
。您可能需要使用更具体的选择器