簡體   English   中英

有沒有辦法在 python selenium 中使用 send_keys 更改文本的顏色?

[英]Is there any way to change the color of a text using send_keys in python selenium?

我在 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()))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM