Skip to content

Commit

Permalink
[#515] REFACTOR: remove command.js.__click impl
Browse files Browse the repository at this point in the history
... as it has not been fully working in context of autocompletion for now (waiting for #518 to progress on this)
  • Loading branch information
yashaka committed Mar 6, 2024
1 parent 3e757e6 commit bc4aea6
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions selene/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,60 +231,6 @@ def func(element: Element):
)

# TODO: should we process collections too? i.e. click through all elements?
@staticmethod
def __click(
entity: Element | None = None, /, *, xoffset=0, yoffset=0
) -> Command[Element]:
def func(element: Element):
element.execute_script(
'''
const offsetX = arguments[0]
const offsetY = arguments[1]
const rect = element.getBoundingClientRect()
function mouseEvent() {
if (typeof (Event) === 'function') {
return new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
clientX: rect.left + rect.width / 2 + offsetX,
clientY: rect.top + rect.height / 2 + offsetY
})
}
else {
const event = document.createEvent('MouseEvent')
event.initEvent('click', true, true)
event.type = 'click'
event.view = window
event.clientX = rect.left + rect.width / 2 + offsetX
event.clientY = rect.top + rect.height / 2 + offsetY
return event
}
}
element.dispatchEvent(mouseEvent())
''',
xoffset,
yoffset,
)

command: Command[Element] = Command(
(
'click'
if (not xoffset and not yoffset)
else f'click(xoffset={xoffset},yoffset={yoffset})'
),
func,
)

if isinstance(entity, Element):
# somebody passed command as `.perform(command.js.click)`
# not as `.perform(command.js.click())`
element = entity
command.__call__(element)

return command

class __ClickWithOffset(Command[Element]):
def __init__(self):
self._description = 'click'
Expand Down

0 comments on commit bc4aea6

Please sign in to comment.