Skip to content Skip to sidebar Skip to footer

Python Selenium - Highlight Element Doesn't Do Anything

I'm trying to highlight elements on the following webpage using python selenium. I'm using the solution posted here: How can I highlight element on a webpage using Selenium-Python?

Solution 1:

Works fine for me. Note that it highlights element (add 2 pixels red border) for 0.3 seconds only, so you might just miss that effect

You can add more parameters to function, like TimeToHighlight, Color, BorderSize:

defhighlight(element, effect_time, color, border):
    """Highlights (blinks) a Selenium Webdriver element"""
    driver = element._parent
    defapply_style(s):
        driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",
                              element, s)
    original_style = element.get_attribute('style')
    apply_style("border: {0}px solid {1};".format(border, color))
    time.sleep(effect_time)
    apply_style(original_style)

and then call as

open_window_elem = driver.find_element_by_id("openwindow")
highlight(open_window_elem, 3, "blue", 5)

This will add blue 5 pixels border to element for 3 seconds

Post a Comment for "Python Selenium - Highlight Element Doesn't Do Anything"