Skip to content

Commit b8bf3f0

Browse files
authored
Merge pull request #102 from itk-dev-rpa/develop
2.11
2 parents 6c2f73a + 98dd2f5 commit b8bf3f0

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.11.0] - 2025-03-24
11+
12+
### Changed
13+
14+
- Eflyt now using resilient browser for login to avoid stale elements
15+
1016
## [2.10.0] - 2025-03-20
1117

1218
### Changed
@@ -208,7 +214,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
208214

209215
- Initial release
210216

211-
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.10.0...HEAD
217+
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.11.0...HEAD
218+
[2.11.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.11.0
212219
[2.10.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.10.0
213220
[2.9.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.9.0
214221
[2.8.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.8.1

itk_dev_shared_components/eflyt/eflyt_login.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
"""Module for logging into Eflyt/Daedalus/Whatchamacallit using Selenium"""
2+
import time
3+
24
from selenium import webdriver
35
from selenium.webdriver.common.by import By
4-
from selenium.common.exceptions import NoSuchElementException
6+
from selenium.webdriver.remote.webelement import WebElement
7+
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException
8+
9+
10+
class ResilientBrowser(webdriver.Chrome):
11+
"""A webdriver.Chrome subclass that retries find_element if the element goes stale."""
12+
def find_element(self, by=By.ID, value = None) -> WebElement:
13+
element = super().find_element(by, value)
14+
time.sleep(0.1)
15+
try:
16+
element.tag_name
17+
except StaleElementReferenceException:
18+
element = super().find_element(by, value)
19+
return element
520

621

7-
def login(username: str, password: str) -> webdriver.Chrome:
22+
def login(username: str, password: str) -> ResilientBrowser:
823
"""Log into Eflyt using a password and username.
924
1025
Args:
@@ -13,8 +28,9 @@ def login(username: str, password: str) -> webdriver.Chrome:
1328
"""
1429
chrome_options = webdriver.ChromeOptions()
1530
chrome_options.add_argument("--disable-search-engine-choice-screen")
16-
browser = webdriver.Chrome(options=chrome_options)
31+
browser = ResilientBrowser(options=chrome_options)
1732
browser.maximize_window()
33+
browser.implicitly_wait(2)
1834

1935
browser.get("https://notuskommunal.scandihealth.net/")
2036
browser.find_element(By.ID, "Login1_UserName").send_keys(username)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "itk_dev_shared_components"
7-
version = "2.10.0"
7+
version = "2.11.0"
88
authors = [
99
{ name="ITK Development", email="[email protected]" },
1010
]

0 commit comments

Comments
 (0)