用于python的Selenium键错误:非

2024-05-13 23:39:59 发布

您现在位置:Python中文网/ 问答频道 /正文

   I want to do move button at some description。

我的代码是:

^{pr2}$

何时开始行动_链条。执行()。它引发了一个异常。在

在线:

action_chains.perform()

错误堆栈跟踪:

  File "/Library/Python/2.7/site-packages/selenium/webdriver/common/action_chains.py", line 83, in perform
    action()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/common/action_chains.py", line 323, in <lambda>
    time.sleep(seconds)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 306, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 459, in execute
    command_info = self._commands[command]
KeyError: None

我该怎么办?在


Tags: inpyexecuteremotepackagesseleniumlinelibrary
1条回答
网友
1楼 · 发布于 2024-05-13 23:39:59

试着把链子断开一点。我觉得你的链子里有太多的东西。 我的动作有问题_链。暂停()命令不受支持。如此使用时间。睡觉()就像你说的那样。在

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import math
import random
import time

options = Options()
options.add_argument(" disable-infobars")
driver = webdriver.Chrome(chrome_options=options)

driver.get('http://whatever_your_url_is')
move_button = driver.find_element_by_id('the_button')

move_x_sum = 0
offset_x = 20
offset_y = 30
action_chains = ActionChains(driver)
while move_x_sum < offset_x - 10:
    move_x = random.randint(5, 10)
    action_chains.move_to_element_with_offset(
        to_element=move_button,
        xoffset=move_x,
        yoffset=offset_y)
    action_chains.click_and_hold(move_button)
    action_chains.perform()
    time.sleep(float(random.randint(300, 500) / 1000))
    move_x_sum += move_x
action_chains.move_to_element_with_offset(
    to_element=move_button,
    xoffset=offset_x - move_x_sum,
    yoffset=offset_y)
action_chains.perform()
time.sleep(2)
driver.quit()

相关问题 更多 >