Selenium(使用python)如何修改元素CSS样式 [英] Selenium (with python) how to modify an element css style

查看:2395
本文介绍了Selenium(使用python)如何修改元素CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用硒.execute_script更改元素的CSS样式(例如:从"visibility: hidden;""visibility: visible;"). (可以通过selenium + python接受其他任何方法).

I'm trying to change CSS style of an element (example: from "visibility: hidden;" to "visibility: visible;") using selenium .execute_script. (any other method through selenium+python would be accepted gracefully).

我的代码:

driver = webdriver.Firefox()
driver.get("http://www.example.com")

elem = driver.find_element_by_id('copy_link')

elem.execute_script(  area of my problem )

要使用网页的CSS,我需要做什么?

what do i need to do in order to play with the CSS of the webpage ?

推荐答案

这里是一个不使用任何jQuery的示例.它将隐藏Google的徽标.

Here is an example without using any jQuery. It will hide Google's logo.

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com")
driver.execute_script("document.getElementById('lga').style.display = 'none';")

例如,可以通过将.style.display设置为"block"来使用相同的想法来显示隐藏的元素.

The same idea could be used to show a hidden element by setting .style.display to "block", for example.

这篇关于Selenium(使用python)如何修改元素CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆