首页 > 解决方案 > How to know changes in color with selenium (python)

问题描述

Am working on this website : here , when u insert a text in the text-area, and click on play button

it gonna take a while then you hear the audio, what i did notice is when the audio is playing the

border around the text-area turns to blue.

what i want to know: is there any way to detect that using selenium on python.

标签: pythonseleniumautomation

解决方案


Yes, you can. This is actually the CSS property "outline".

The code below clicks the button and prints the outline, which is "rgb(15, 97, 254) solid 2px".

import time
from selenium import webdriver
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager

def scrape_products():
    options = webdriver.ChromeOptions()
    options.add_argument('start-maximized')
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option("useAutomationExtension", False)

    browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)

    browser.get("https://www.ibm.com/demos/live/tts-demo/self-service/home")
    time.sleep(2)

    play = browser.find_element_by_id('btn')
    play.click()
    time.sleep(10)

    textarea = browser.find_element_by_id('text-area')
    outline = textarea.value_of_css_property('outline')

    print(outline)


if __name__ == "__main__":
    scrape_products()

推荐阅读