I need to reduce time to perform selenium action chain
Asked Answered
S

1

6

I am currently using action chains in selenium using Python3 to perform clicks on an element. Performing the two action chains required currently takes ~0.6 seconds I need them to be executed in < 0.1 seconds.

Until now I have been using pyautogui and setting pyautogui.PAUSE to 0. This allows me to pull off both clicks in less than 0.05 seconds but it because it is actually moving the mouse, I cannot use the computer while it is testing in that manor. I also cannot run multiple tests concurrently using pyautogui. Throughout my debugging I have concluded that the bottleneck is the execution step.

Now correct me if I am horrifically wrong, but in my understanding it would seem that selenium should be faster than pyautogui seeing as how it simply skips a step and goes straight to the browser. Because of this, I am thinking that selenium might be artificially slowing down the action chains. If so, does anybody know how to keep it from doing that?

Bellow, I have added the code that I am currently using. Takes ~0.3 seconds per click.

action_1 = webdriver.common.action_chains.ActionChains(driver)
action_1.move_to_element_with_offset(e, offset[0], offset[1])
action_1.click()
action_1.perform()

[Update]: I separated the action chains into individual actions and found the following:

  • calculating the action chains takes 0.008-0.009 seconds
  • moving to the first click takes 0.25-0.27 seconds
  • clicking the first takes 0.013-0.014 seconds
  • moving to the second click takes 0.25-0.27 seconds
  • clicking the second takes 0.06-0.09 seconds
Shaduf answered 7/9, 2019 at 23:59 Comment(2)
Selenium doesn't slowdown the actions, the default is 0... only if you explicit add it, like action_1.pause(1) I'm really curious about an answer to this question also.Cite
I have the same issue, it didn't appear in the older chrome versions for some reason.Asphyxia
A
1

Python selenium module you can set the duration of the mouse movement by setting the following property on the action chain:

action_chain.w3c_actions.pointer_action._duration = 0

However, this is just a workaround. Ideally, we should avoid modifying fields marked private. ( variable/class names starting with underscore ("_") are considered private ).

Alves answered 8/6, 2022 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.