【问题标题】:Error on waiting for element to load using explicit wait in selenium python在 selenium python 中使用显式等待等待元素加载时出错
【发布时间】:2018-07-17 07:05:09
【问题描述】:
element = WebDriverWait(driver, 50).until(EC.presence_of_element_located((By.XPATH,"//*[@id='button-1023-btnEl']")))

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

var.click()
  File "C:\Users\ankij\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\ankij\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\ankij\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\ankij\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.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>

【问题讨论】:

    标签: python-3.x selenium webdriver


    【解决方案1】:

    您需要对 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
    

    【讨论】:

      【解决方案2】:

      尝试替换:

      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")))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-05
        • 1970-01-01
        • 2018-07-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多