Skip to content

Python method ActionChains.pause implemented incorrectly #4832

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
hugodcpires opened this issue Oct 9, 2017 · 2 comments
Closed

Python method ActionChains.pause implemented incorrectly #4832

hugodcpires opened this issue Oct 9, 2017 · 2 comments

Comments

@hugodcpires
Copy link

hugodcpires commented Oct 9, 2017

Meta -

OS:
Windows 10
Selenium Version:
3.6.0
Browser:
Chrome
Browser Version:
61.0.3163.100 (Official Build) (64-bit)

Expected Behavior -

ActionChains.pause to work as described in documentation.

Actual Behavior -

Traceback.

Steps to reproduce -

The following code:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("http://www.google.com")
elem = driver.find_element_by_name("q")
actions = ActionChains(driver)
actions.key_down(Keys.CONTROL, elem)
actions.pause(1)
actions.key_up(Keys.CONTROL, elem)
actions.perform()
driver.close()

generates the following error:

Traceback (most recent call last):
File "C:/Users/hugod/PycharmProjects/action_chain_pause/main", line 108, in
actions.perform()
File "C:\Users\hugod\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 83, in perform
action()
File "C:\Users\hugod\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 323, in
time.sleep(seconds)
File "C:\Users\hugod\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\hugod\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 459, in execute
command_info = self._commands[command]
KeyError: None

Process finished with exit code 1

I found issue #4795 while looking for bug reports. The resulting traceback is slightly different though and I wasn't sure if it has the same root cause or is the same issue altogether. For me, replacing this code (in action_chains.py):

def pause(self, seconds):
    if self._driver.w3c:
        self.w3c_actions.pointer_action.pause(self, seconds)
        self.w3c_actions.key_action.pause(self, seconds)
    else:
        self._actions.append(lambda: self._driver.execute(
            time.sleep(seconds)
        ))
    return self

with this:

def pause(self, seconds):
    if self._driver.w3c:
        self.w3c_actions.pointer_action.pause(self, seconds)
        self.w3c_actions.key_action.pause(self, seconds)
    else:
        self._actions.append(lambda: 
            time.sleep(seconds)
        )
    return self

fixed the issue. No traceback and the behaviour looks as desired (a pause between actions in the action chain execution).

Apologies if this is a duplicate.

@lmtierney
Copy link
Member

Duplicate of #4795. See my comment in that issue referencing the commit that fixes it. It just hasn't been released yet, it will be in the next release.

@hugodcpires
Copy link
Author

Ah yes, looks good. Cheers!

@lock lock bot locked and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants