Skip to content

Commit

Permalink
select_option() fix the event handlers not dispatched when programmat…
Browse files Browse the repository at this point in the history
…ically selecting option
  • Loading branch information
ultrafunkamsterdam authored Aug 2, 2024
1 parent 0828159 commit 2957c87
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nodriver/core/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,22 @@ async def focus(self):
return await self.apply("(element) => element.focus()")

async def select_option(self):
"""for form (select) fields. when you have queried the options you can call this method on the option object
"""
for form (select) fields. when you have queried the options you can call this method on the option object.
02/08/2024: fixed the problem where events are not fired when programattically selecting an option.
calling :func:`option.select_option()` will use that option as selected value.
does not work in all cases.
"""
if self.node_name == "OPTION":
return await self.apply("(o) => o.selected = true")
await self.apply(
"""
(o) => {
o.selected = true ;
o.dispatchEvent(new Event('change', {view: window,bubbles: true}))
}
""")

async def set_value(self, value):
await self._tab.send(cdp.dom.set_node_value(node_id=self.node_id, value=value))
Expand Down

0 comments on commit 2957c87

Please sign in to comment.