首页 > 解决方案 > 元素点击拦截硒进行自动化

问题描述

我正在尝试做一个自动为 Zoom 找到可用空间的机器人(所以我可以拖钓,因为我很无聊)。

它可以工作,但有时会收到提交按钮单击被拦截的错误。我希望我的程序在出现错误后继续运行,但它只是停止了。我怎样才能解决这个问题?

这是代码:

    browser.get("https://www.zoomus.cn/j/1313141151?_x_zm_rtaid=GJwf9jNWTHasYv14WqiBZg.1593889587120.4853db3668ae0d51573cd748d7f1ded4&_x_zm_rhtaid=338")


class Buttons:
    ID_Box = browser.find_element_by_id("join-confno")
    Submit_BTN = browser.find_element_by_id("btnSubmit")


def CheckElement_Exist():
    try:
        browser.find_element(By.ID, "join-confno")
    except NoSuchElementException:
        return False
        pass
    return True


while CheckElement_Exist():
    Number_Random = choices(availableSymbols_Code, k=randint(9 + 5, 11 + 5))
    attempts += 1
    Buttons.ID_Box.send_keys(''.join(Number_Random))
    Buttons.Submit_BTN.click()
    time.sleep(0.5)
    Buttons.ID_Box.clear()
    time.sleep(3.5)


time_end = time.time()
time_took = round(time_end - time_end, 2)
Saved_Number = Number_Random
print(Fore.GREEN + "Room found in " + Style.RESET_ALL + Fore.RED + time_took + Style.RESET_ALL + Fore.GREEN
      + " seconds. Number is: " + Style.RESET_ALL + Fore.RED + Saved_Number + Style.RESET_ALL + Fore.GREEN + ".")

这是错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a id="btnSubmit" role="button" href="javascript:;" class="btn btn-primary user submit disabled" disabled="disabled">...</a> is not clickable at point (324, 357). Other element would receive the click: <div class="controls">...</div>

标签: pythonselenium

解决方案


正如错误清楚地表明的那样,

其他元素会收到点击:div class="controls"

它可能由于各种原因而发生,

  1. 可能是您的提交按钮不在页面视图中,在这种情况下,请考虑尝试在Buttons.Submit_BTN.click()之前使用任何一个代码段:
actions = ActionChains(driver)
actions.move_to_element(Submit_BTN).perform()

或替代此:

driver.execute_script("arguments[0].scrollIntoView();", Submit_BTN);
  1. 否则,您可以尝试将“ENTER”键发送到Submit_BTN元素,而不是单击按钮:
Submit_BTN.send_keys(u'\ue007');
  1. 如果上述选项不起作用,则提交按钮可以有一个包装元素。尝试在页面上找到 div class="controls" 元素以了解此错误。

希望这可以帮助你巨魔!;)


推荐阅读