【问题标题】:Can't Click Element无法点击元素
【发布时间】:2019-09-17 05:45:34
【问题描述】:

我正在尝试点击这个元素, 但出现类似

的错误
>> ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (271, 705)

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@action="/battle/"]/div/input[2]')))
        element.click();

这也无助于获取超时异常。我认为元素有点覆盖

与:

[driver.find_element_by_xpath('//[@action="/battle/"]/div/input[2]').click()]

<form action="/battle/" method="post" name="4416" id="4416" onsubmit="get('/battle/', '', this); disableSubmitButton(this); return false;"><div class="battleView" style="float:left; width:65%;"><h3 class="heading-maroon no-right-border-rad margin-right-2">Attack Results</h3><table cellpadding="0" cellspacing="0" style="width: 80%; text-align: center; margin: 0 auto;">
...
</tbody></table><input type="hidden" class="button-maroon button-small" name="action" value="attack">

<input type="submit" class="button-maroon button-small" value=" Attack .. "></div>
</form>

【问题讨论】:

    标签: python selenium click element interrupted-exception


    【解决方案1】:

    它似乎在错误消息中显示 X/Y 坐标 (271,705)。我会尝试使用像 AppRobotic 这样的宏产品来查找您在使用 XPATH、移动鼠标​​或发送击键 TABS 时遇到问题的元素的 X/Y 坐标,然后单击它。一个简单的例子:

    import win32com.client
    x = win32com.client.Dispatch("AppRobotic.API")
    from selenium import webdriver
    
    # navigate to Yahoo
    driver = webdriver.Firefox()
    driver.get('https://www.yahoo.com') 
    # sleep 1 second
    x.Wait(1000)
    
    link = driver.find_element_by_link_text('Mail')
    if len(link) > 0
        link[0].click()
    else
        x.Wait(3000)
        # use UI Item Explorer to get X,Y coordinates of Mail box
        x.MoveCursor(271,705)
        # click inside Search box
        x.MouseLeftClick
    
        # could also try tabbing over and pressing Enter
        x.Type("{TAB}")
        x.Type("{ENTER}")
    

    另一个想法是先尝试使用 Selenium 滚动到元素:

    from selenium.webdriver.common.action_chains import ActionChains
    
    element = driver.find_element_by_xpath('//[@action="/battle/"]/div/input[2]')
    actionchains = ActionChains(driver)
    actionchains.move_to_element(element).perform()
    

    【讨论】:

    • 亲爱的,谢谢您的回答,除了“Robotic.API”之外,一切都很好,您能解释一下那部分吗?我需要额外的东西才能使用这些代码吗?
    猜你喜欢
    • 2018-04-02
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多