【问题标题】:selenium wedriver program can not go onselenium webdriver程序无法继续
【发布时间】:2020-06-30 13:45:18
【问题描述】:

我正在尝试使用 webdriver 单击登录按钮,页面已正确转换。但程序停止并出现问题“selenium.common.exceptions.ElementNotInteractableException:消息:元素不可交互” 这是发生问题的代码

browser.find_element_by_xpath(
            '//*[@id="emap-rsids-content"]/div/div[3]/div/div[1]/div/div/div/input').send_keys(uid)
        browser.find_element_by_xpath(
            '//*[@id="emap-rsids-content"]/div/div[3]/div/div[2]/div/div/div/input').send_keys(pwd)
        # click to sign in

        browser.find_element_by_xpath('//*[@id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').send_keys(Keys.ENTER)
        time.sleep(3)
        browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()
这是回溯

Traceback (most recent call last):
  File "C:/Users/14638/Desktop/auto_sign_zzu_jksb-master/auto_sign.py", line 68, in sign_in
    time.sleep(3)
  File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  (Session info: chrome=83.0.4103.116)
第 68 行是 time.sleep(3),点击有效并转换到新页面,但仍然出现按钮元素是可交互的。 我尝试了两种方法,一种是

''' browser.find_element_by_xpath('//*[@id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').click() '''

另一个是

''' pages=browser.find_element_by_xpath('//*[@id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button') browser.execute_script("arguments[0].click();", pages) '''

还是不行

【问题讨论】:

  • 我认为Enter 确实提交了您的登录表单,然后单击无法正常工作,因为没有可单击的元素?

标签: python selenium selenium-webdriver


【解决方案1】:

我认为您正在尝试单击未完全加载的元素。您要做的就是等到发生这种情况。

首先导入这些文件

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

然后登录后添加这个。

WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, '/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]')))

那就做吧

browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()

【讨论】:

    【解决方案2】:

    你需要更新page_source:

    browser.find_element_by_xpath(
                '//*[@id="emap-rsids-content"]/div/div[3]/div/div[1]/div/div/div/input').send_keys(uid)
            browser.find_element_by_xpath(
                '//*[@id="emap-rsids-content"]/div/div[3]/div/div[2]/div/div/div/input').send_keys(pwd)
            # click to sign in
    
            time.sleep(5) # add some time to load the page
            browser.get(browser.current_url)
            time.sleep(1)
    
            browser.find_element_by_xpath('//*[@id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').send_keys(Keys.ENTER)
            time.sleep(3)
            browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()
    

    【讨论】:

      猜你喜欢
      • 2014-01-04
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 2018-09-01
      • 2020-12-09
      • 2013-09-14
      相关资源
      最近更新 更多