I have been handed over a existing selenium framework which uses python for scripting. For debugging(& other) purposes, I would like to highlight the element on which action is being taken currently (input box, link, drop-down etc.)
Though I could find solutions to define a function and calling the function wherever I need to highlight the element(as examples given below), what I need is a solution at the framework level.
Is it possible to implement any solution at the framework / script level in Python (or any other language which can be integrated with python scripts), so that I don't have to call the functions explicitly.
PS I am just beginning to use Python, so excuse me if its a simple/straight forward. Will appreciate if someone can point me to any existing solution or can provide their own solution.
I haven't tried this code, but this should work.
import time
def highlight(element):
"""Highlights (blinks) a Selenium Webdriver element"""
driver = element._parent
def apply_style(s):
driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",element, s)
original_style = element.get_attribute('style')
apply_style("background: yellow; border: 2px solid red;")
time.sleep(.3)
apply_style(original_style)
Hope this helps. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.