python - Python Selenium 查找所有 CSS 元素并替换所有
问题描述
我想在自动更改页面主题颜色的同时使用 Python Selenium 更改 CSS 元素样式。例如,页面元素如下:
<div style="background: #e7e7e7">
<div style="border-bottom: #e7e7e7; border-top: #e7e7e7">
我想将颜色从 更改#e7e7e7
为#318c89
,这意味着我需要e7e7e7
在 HTML 脚本中找到所有内容并将所有内容替换为,#318c89
但我不知道该怎么做。
提前致谢。
解决方案
尝试这个:
script = "document.body.innerHTML = document.body.innerHTML.replaceAll('#e7e7e7', '#318c89')"
driver.execute_script(script)
推荐阅读
- wpf - 如何将资源转换为 xaml 文件中的其他类型?
- tabs - IONIC 4 选项卡导航
- c# - 包括所有具有递归属性的导航属性 EF Core
- javascript - jquery keyup show/hide stay shown when backspaced
- datetimepicker - DateTimePicker 组件,C++ Builder 6
- javascript - Highchart 向上钻取功能现在可以在 reactjs 中使用
- javascript - jQuery stop() 函数等效于纯 javascript
- javascript - 使用 rjxs 而不是 setTimeout 函数订阅的更优雅的方式?
- python - Flask多个参数如何在从一个url查询数据库的多个列时避免多个if语句
- python - 如果在程序运行时重新启动,使用 configparser 写入 .ini 文件会导致一个空文件