Skip to content

I've created a function to CTRL+A + DELETE #14

Description

@pi-infected

Hi,

I ran in a case where I need to delete the text of an input before writing into it, and deleting the innerHTML would just mess with the rest of the scripts. So I've made a function for CTRL+A+Delete. I thought it is a common case and that people here could use this code.

from botasaurus_driver import cdp

def send_ctrl_a_delete(element):
  element._tab.send(cdp.input_.dispatch_key_event(
    type_="keyDown",
    modifiers=2,  # Ctrl = 2
    code="KeyA",
    key="a",
    windows_virtual_key_code=65 
  ))
  
  element._tab.send(cdp.input_.dispatch_key_event(
    type_="keyUp",
    modifiers=2,
    code="KeyA",
    key="a",
    windows_virtual_key_code=65
  ))
  
  element._tab.send(cdp.input_.dispatch_key_event(
    type_="keyDown",
    code="Delete",
    key="Delete",
    windows_virtual_key_code=46
  ))
  
  element._tab.send(cdp.input_.dispatch_key_event(
    type_="keyUp",
    code="Delete",
    key="Delete",
    windows_virtual_key_code=46
  ))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions