# SeleniumLibrary Screenshot on Failure with python

**URL:** <https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707>\
**Category:** SeleniumLibrary\
**Created:** [24 March 2025 18:13 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707 "2025-03-24T18:13:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmtan01](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@wmtan01](https://forum.robotframework.org/u/wmtan01)\
**Post date:** [24 March 2025 18:13 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707/1 "2025-03-24T18:13:53Z")

</div>

Hi,

We use Robot Framework and SeleniumLibrary for most of our testing. Recently we started exploring using python more specially for building more complex keywords. We noticed that when these keywords fail, even when they fail when calling SeleniumLibrary keywords, they do not log screenshots.

As an example:  
When implemented with Robot Framework:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/7/7d0e6f9c9ece4235a848c0bf4f2ec783d0349a20.png)

When implemented with Python:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/9/97d095c600ab8e558e52fa1748c415175d4ba417.png)

The logging still happens but no screenshot is taken at failure. Reading through the code, it seems the handler in SeleniumLibrary doesn’t trigger since it’s not technically a SeleniumLibrary keyword that failed. Any ideas on how we can still get screenshots on failure even when calling SeleniumLibrary keywords in a python library?

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [24 March 2025 18:38 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707/2 "2025-03-24T18:38:15Z")

</div>

> [@wmtan01](#):
>
> when calling SeleniumLibrary keywords in a python library?

Maybe you need to ensure your keywords in python library use `try/except` and call Capture Screenshot when failing.

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [24 March 2025 18:53 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707/3 "2025-03-24T18:53:56Z")

</div>

Run on failure functionally is built by using Robot Framework dynamic library API. Therefore if you directly call methods implementing keywords, you are bypassing this feature and you need to implement this by yourself. Luckily it’s easy to do, example by using Python decorator [Decorators in Python - GeeksforGeeks](https://www.geeksforgeeks.org/decorators-in-python/)

---

<div class="post-metadata">

**Author:** ![wmtan01](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@wmtan01](https://forum.robotframework.org/u/wmtan01)\
**Post date:** [24 March 2025 20:18 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707/4 "2025-03-24T20:18:22Z")

</div>

Yeah, this was the way and @aaltat 's answer with this Try/Catch did to the trick. Thanks!

---

<div class="post-metadata">

**Author:** ![wmtan01](https://avatars.discourse-cdn.com/v4/letter/w/c37758/32.png) [@wmtan01](https://forum.robotframework.org/u/wmtan01)\
**Post date:** [24 March 2025 20:19 UTC](https://forum.robotframework.org/t/seleniumlibrary-screenshot-on-failure-with-python/8707/5 "2025-03-24T20:19:01Z")

</div>

That did the trick. Thanks for the answer! Had to extend from the DynamicCore so i can define my own handling for run\_keyword.
