Skip to content

Perform a long key press using action chain #3781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SortedShuffle opened this issue May 29, 2025 · 1 comment
Closed

Perform a long key press using action chain #3781

SortedShuffle opened this issue May 29, 2025 · 1 comment
Labels
invalid usage You may need to change what you're doing question Someone is looking for answers

Comments

@SortedShuffle
Copy link

I need to perform a long key press on a website for about 3 seconds.

Reading the documentation I found self.press_up_arrow(selector="html", times=1, by="css selector") but increasing the times parameter isn't working for me. So, I tried using the following:

from seleniumbase import SB
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

with SB(
        #demo=True,
        ad_block=True
    ) as sb:
        sb.open("https://my.url")
        actions = ActionChains(sb)
        actions.key_down(Keys.ARROW_LEFT).pause(3).key_up(Keys.ARROW_LEFT)
        actions.perform()

Unfortunately I get the error:

  ...
  File "/some/file.py", line xy, in perform
    actions.perform()
    ~~~~~~~~~~~~~~~^^
  File "/.venv/lib/python3.13/site-packages/selenium/webdriver/common/action_chains.py", line 94, in perform
    self.w3c_actions.perform()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/.venv/lib/python3.13/site-packages/selenium/webdriver/common/actions/action_builder.py", line 170, in perform
    self.driver.execute(Command.W3C_ACTIONS, enc)
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'BaseCase' object has no attribute 'execute'

What should I try?

@mdmintz mdmintz added question Someone is looking for answers invalid usage You may need to change what you're doing labels May 29, 2025
@mdmintz
Copy link
Member

mdmintz commented May 29, 2025

ActionChains expects a driver object, not an sb object.
You should be passing in sb.driver into it, not sb.
(ActionChains is from the selenium library, not the seleniumbase one.)

@mdmintz mdmintz closed this as completed May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid usage You may need to change what you're doing question Someone is looking for answers
Projects
None yet
Development

No branches or pull requests

2 participants