python+selenium定位到密码输入框,但是无法输入密码是怎么回事
代码如下
#coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("http://10.0.12.211:8081/p2p/jsp/login.jsp")
#driver.find_element_by_id("login_anchor").click()
driver.find_element_by_id("j_username").clear()
driver.find_element_by_id("j_username").send_keys("test01")
time.sleep(5)
driver.find_element_by_id("x_password").clear()
driver.find_element_by_id("x_password").send_keys("12345678")
运行报错如下:
Traceback (most recent call last):
File "C:/Users/ebt/PycharmProjects/EBT/test.py", line 12, in <module>
driver.find_element_by_id("x_password").send_keys("12345678")
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 318, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing})
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 402, in _execute
return self._parent.execute(command, params)
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 175, in execute
self.error_handler.check_response(response)
File "D:\Python27\lib\site-packages\selenium-2.45.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=53.0.2785.101)
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)
被测页面如下:
解决了,就提供第二种简单思路,点击,调用硬件操作,输入密码 求各位大神来解答,感谢!! 错误信息里有selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
你尝试加个等待,等待这个元素可见(is_displayed)或可用(is_enabled)
元素取错了,你把元素换成j_password,顺便吐槽下你们的前端略low;P
driver.find_element_by_id("j_password").clear()
driver.find_element_by_id("j_password").send_keys("12345678") joykao 发表于 2016-10-11 11:09
元素取错了,你把元素换成j_password,顺便吐槽下你们的前端略low
driver.find_element_by_id("j_pa ...
元素没错,谢谢 菜鸟@大虾 发表于 2016-10-11 10:02
错误信息里有selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
...
已经解决了,谢谢指点 经常会出现因为不加等待而找不到元素的情况,用sleep方法即可 thread.sleep(3000); 812745312 发表于 2016-10-11 14:45
解决了,就提供第二种简单思路,点击,调用硬件操作,输入密码
楼主,你怎么解决的,点击,调用硬件操作是什么意思?
页:
[1]