将所有"display: none"更改为使用 Selenium Python "display: block"



我有一个网站,我想将所有带有"display: none"的元素更改为"display: block"。我想用Python Selenium实现操作的自动化。我已经找到了这样做的方法,但只有当您有类名并且只有一个元素需要更改时,这种方法才有效。

这应该可以工作,但会消耗大量时间。最好是通过更具体的xpath:来缩小元素的范围

every_element = driver.find_elements_by_xpath("//*")
for element in every_element:
display_prop = element.value_of_css_property('display')
if display_prop == 'none':
driver.execute_script("arguments[0].style.display = 'block';", element)

相关内容

最新更新