在selenium python中使用显式等待等待加载元素时出错


element = WebDriverWait(driver, 50).until(EC.presence_of_element_located((By.XPATH,"//*[@id='button-1023-btnEl']")))

使用此代码,我得到错误如下:

var.click()
File "C:UsersankijAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverremotewebelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:UsersankijAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverremotewebelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:UsersankijAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverremotewebdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:UsersankijAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverremoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <span id="button-1023-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="height:auto;" class="x-btn-button x-btn-button-login-large x-btn-text    x-btn-button-center ">...</span> is not clickable at point (1660, 590). Other element would receive the click: <div class="x-component x-border-box x-mask x-component-default x-focus x-component-focus x-component-default-focus" role="status" id="loadmask-1024" tabindex="0" componentid="loadmask-1024" style="width: 1920px; height: 930px; right: auto; left: 0px; top: 0px;">...</div>

您需要对xpath进行细化,如下所示:

element = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH,"//span[@class='x-btn-button x-btn-button-login-large x-btn-text x-btn-button-center' and @id='button-1023-btnEl']")))

注意:您必须添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

尝试替换:

element = WebDriverWait(driver, 50).until(EC.presence_of_element_located((By.XPATH,"//*[@id='button-1023-btnEl']")))

带有:

element = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.ID,"button-1023-btnEl")))

最新更新