admin管理员组文章数量:1415099
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.
- Selenium webdriver highlight element before clicking
- /
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.
P.S. 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 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.
- Selenium webdriver highlight element before clicking
- https://seleniumwithjavapython.wordpress./selenium-with-python/intermediate-topics/playing-with-javascript-and-javascript-executor/highlighting-a-web-element-on-webpage/
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.
P.S. 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.
Share Improve this question asked Aug 1, 2017 at 14:12 NikNik 172 silver badges6 bronze badges 4- I don't understand the need to highlight the element for debugging. logs should be enough to understand what when wrong. Also the solution which has provided by santosh will slow down your execution. (.3x number of elements) – Gaurang Shah Commented Aug 1, 2017 at 14:36
- I understand but as I said I am new to Python (done very little programming so far) so highlighting of element makes it easier for me to debug the failure points. I agree, I'll get fortable with debugging using logs after a few months but for now I can only appreciate any solution to my problem. – Nik Commented Aug 1, 2017 at 14:45
- There is no easy solution for this. either you write wrapper for each and every action for which you want to highlight the element, or before you do any action call this method in your tests manually. either way it's costly, it would be costly when you will have to disable that as well. – Gaurang Shah Commented Aug 2, 2017 at 7:57
- Thanks @GaurangShah – Nik Commented Aug 4, 2017 at 16:48
1 Answer
Reset to default 4I 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.
Source - https://gist.github./dariodiaz/3104601
本文标签: javascriptHow can I highlight element on a webpage using SeleniumPythonStack Overflow
版权声明:本文标题:javascript - How can I highlight element on a webpage using Selenium-Python? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745168021a2645800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论