python - 有没有办法在 python selenium 中使用 send_keys 更改文本的颜色?
问题描述
我在 python 中有一个脚本(web-scraper)——也使用selenium
——在某些时候我必须填写一些字段。在我填写之后,我附上了一个带有lorem
模块的随机段落。关键是我想隐藏这一段,例如,给它一些透明度或将颜色更改为白色(因为背景是白色的)。
我的代码是这样的:
# import selenium, lorem, create the webdriver object,
# get the url, etc.
driver.find_element_by_id('some_id').send_keys(
'some_string' + lorem.paragraph())
lorem.paragraph()
那么,有什么方法可以在不影响第一个字符串的易读性的情况下将颜色(或使其透明)更改为第二个字符串?
我是 python selenium 的新手,如果有人能提供帮助,我将不胜感激。提前致谢。任何答案将不胜感激。
解决方案
您可以创建一个函数来将 HTML 标记附加到您的文本中。就像是:
def hide(text):
return '<h1 style="color:white">' + text + '</h1>'
然后用它来美白你的文字
# import selenium, lorem, create the webdriver object,
# get the url, etc.
driver.find_element_by_id('some_id').send_keys(
'some_string' + hide(lorem.paragraph()))
推荐阅读
- c# - gmail不再发送电子邮件
- typescript - 打字稿:将类型定义为除函数之外的任何类型
- kotlin - 如何结合 JUnit4 @RunWith(Parameterized.class) 和 JUnit5 @ParameterizedTest
- asp.net - 无法从 Angular 将文件作为 FormData 上传到 ASP.net
- ruby-on-rails - 创建“本月”查询轨道
- mysql - 连接到 phpMyAdmin?
- python - 如何下载beautifulsoup包python
- opencv - 我错过了立体声校准的东西吗?
- vue.js - props 不能用 v-bind 传递多个数据
- python - 为什么一次在两个文件/模块上使用导入会给我错误,但当我只对一个文件/模块执行时却不会?