seleniumhq.github.io
seleniumhq.github.io copied to clipboard
Add python example to Selenium webdriver support listener
User description
Description
Add python example for webdriver listener support.
Motivation and Context
Make site more comprehensive and it helpful to newer.
Types of changes
- [ ] Change to the site (I have double-checked the Netlify deployment, and my changes look good)
- [x] Code example added (and I also added the example to all translated languages)
- [x] Improved translation
- [ ] Added new translation (and I also added a notice to each document missing translation)
Checklist
- [x] I have read the contributing document.
- [x] I have used hugo to render the site/docs locally and I am sure it works.
My test
excute:
pytest tests/support/test_listener.py --cache-clear -s
output:
================================================================================= test session starts ==================================================================================
platform linux -- Python 3.10.12, pytest-8.3.4, pluggy-1.5.0
rootdir: /home/weiensong/data/repo/seleniumhq.github.io/examples/python
plugins: trio-0.8.0, rerunfailures-14.0
collected 4 items
tests/support/test_listener.py before_navigate_to: https://www.selenium.dev/selenium/web/
after_navigate_to: https://www.selenium.dev/selenium/web/
before_navigate_to: https://www.selenium.dev/selenium/web/clicks.html
after_navigate_to: https://www.selenium.dev/selenium/web/clicks.html
before_navigate_back
after_navigate_back
before_navigate_forward
after_navigate_forward
before_quit
after_quit
['before_navigate_to', 'after_navigate_to', 'before_navigate_to', 'after_navigate_to', 'before_navigate_back', 'after_navigate_back', 'before_navigate_forward', 'after_navigate_forward', 'before_quit', 'after_quit']
.before_navigate_to: https://www.selenium.dev/selenium/web/clicks.html
after_navigate_to: https://www.selenium.dev/selenium/web/clicks.html
before_find
after_find
before_click
after_click
before_close
after_close
['before_navigate_to', 'after_navigate_to', 'before_find', 'after_find', 'before_click', 'after_click', 'before_close', 'after_close']
.before_navigate_to: https://www.selenium.dev/selenium/web/inputs.html
after_navigate_to: https://www.selenium.dev/selenium/web/inputs.html
before_find
after_find
['before_navigate_to', 'after_navigate_to', 'before_find', 'after_find']
before_change_value
after_change_value
.before_navigate_to: https://www.selenium.dev/selenium/web/
after_navigate_to: https://www.selenium.dev/selenium/web/
before_find
on_exception
Exception: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="no_type"]"}
(Session info: chrome=131.0.6778.204); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:
#0 0x5e8de94841fa <unknown>
#1 0x5e8de8f94810 <unknown>
#2 0x5e8de8fe3506 <unknown>
#3 0x5e8de8fe37a1 <unknown>
#4 0x5e8de9028c24 <unknown>
#5 0x5e8de90075ad <unknown>
#6 0x5e8de9026007 <unknown>
#7 0x5e8de9007323 <unknown>
#8 0x5e8de8fd5de0 <unknown>
#9 0x5e8de8fd6dbe <unknown>
#10 0x5e8de945012b <unknown>
#11 0x5e8de94540c7 <unknown>
#12 0x5e8de943d6cc <unknown>
#13 0x5e8de9454c47 <unknown>
#14 0x5e8de942267f <unknown>
#15 0x5e8de9473288 <unknown>
#16 0x5e8de9473450 <unknown>
#17 0x5e8de9483076 <unknown>
#18 0x743768294ac3 <unknown>
before_navigate_to: https://www.selenium.dev/selenium/web/inputs.html
after_navigate_to: https://www.selenium.dev/selenium/web/inputs.html
before_find
after_find
['before_navigate_to', 'after_navigate_to', 'before_find', 'on_exception', 'before_navigate_to', 'after_navigate_to', 'before_find', 'after_find']
before_execute_script
after_execute_script
.
================================================================================== 4 passed in 10.54s ==================================================================================
PR Type
Tests, Documentation
Description
-
Added Python tests for Selenium WebDriver event listeners.
- Implemented
MyListenerclass to log WebDriver events. - Created multiple test cases to validate listener functionality.
- Implemented
-
Updated documentation to include Python examples for event listeners.
- Added code snippets for defining and using listeners.
- Translated updates into multiple languages (Japanese, Portuguese, Chinese).
Changes walkthrough 📝
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Tests |
| ||||||||
| Documentation |
|
Need help?
Type /help how to ...in the comments thread for any questions about Qodo Merge usage.Check out the documentation for more information.
Deploy request for selenium-dev pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | 2e14899cd2c64c37cbec2968d8714a4d97e1a671 |
PR Reviewer Guide 🔍
Here are some key observations to aid the review process:
|
🎫 Ticket compliance analysis ❌ 8 - Not compliant Non-compliant requirements:
|
| ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewResource Cleanup
|
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| General |
Add error handling and cleanupAdd error handling and cleanup in test_navigate_and_quit() to ensure driver is examples/python/tests/support/test_listener.py [86-95]
Suggestion importance[1-10]: 8__ Why: The suggestion adds important error handling with try/finally to ensure the WebDriver is properly closed even if assertions fail, preventing resource leaks and improving test reliability. | Medium |
| Possible issue |
Ensure proper driver cleanupAdd error handling in test_execute_script_and_exception() to properly close the examples/python/tests/support/test_listener.py [141-155]
Suggestion importance[1-10]: 8__ Why: The suggestion adds critical cleanup with try/finally block to ensure WebDriver is properly closed after test completion, preventing resource leaks and improving test robustness. | Medium |
| ||
@titusfortner Hi, who will come to review my code and merge it into SeleniumHQ.