python - selenium wedriver程序无法继续
问题描述
我正在尝试使用 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)
''' 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) '''
但还是不行
解决方案
我认为您正在尝试单击未完全加载的元素。您要做的就是等到发生这种情况。
首先导入这些文件
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()
推荐阅读
- mysql - 如何在mysql中将点添加到多边形或几何的所有点?
- python - Python 3.7 导入命令出现奇怪的 Pylint 错误
- ios - MKAnnotationView:在 annotationView 下方有文本并渲染 View
- javascript - 基于参数的单例模式在javascript中创建promise
- html - 根据元素数量调整元素大小
- python - tf.data.Dataset + tf.lookup.index_table_from_file 导致“表未初始化”错误
- html - 与 Wordpress 中的自定义 CSS 和重力形式对齐
- android - 具有不同本地和远程行为的存储库模式
- python - 使用用户定义函数时如何让两个函数返回?
- asp.net-core - ASP.NET Core 如何在第一次运行时初始化连接字符串?