Currently, if you want to focus an element in Pylenium, you either have to perform some random action on the element or use the Actions class from Selenium. Both work, but it's probably better to have a convenient method to achieve this.
# Current solutions which don't feel so great
## Random action
py.get("#button").hover()
---or---
## Actions class
element = py.get("#button")
actions = Actions(py.webdriver)
actions.move_to_element(element).perform()
Solutions
I recommend adding a new .focus() method to our Element class instead!
Solution 1: Use Selenium's Action class
# Something like this under the Element class
def focus(self) -> "Element":
actions = Actions(self.py.webdriver)
actions.move_to_element(self.webelement).perform()
return self
Solution 2: Use javascript to do the focus
# Something like this under the Element class
def focus(self) -> "Element":
javascript = "js that does the focus"
self.py.execute_script(javascript, self.webelement)
return self
With a solution in place, focusing on an element feels much more explicit and makes sense 🎉
Problem
Currently, if you want to focus an element in Pylenium, you either have to perform some random action on the element or use the
Actions
class from Selenium. Both work, but it's probably better to have a convenient method to achieve this.Solutions
I recommend adding a new
.focus()
method to ourElement
class instead!Solution 1: Use Selenium's Action class
Solution 2: Use javascript to do the focus
With a solution in place, focusing on an element feels much more explicit and makes sense 🎉