gpt4 book ai didi

python - Selenium Python ElementNotVisibleException

转载 作者:行者123 更新时间:2023-12-01 09:10:58 27 4
gpt4 key购买 nike

我正在使用 Selenium 和 Python,并且我正在尝试填写登录表单,我已经成功填写用户名字段,但无法填写密码。这是 HTML:

<div class="loginNotVodafone" style="">

<form id="loginNotVodafone" name="loginNotVodafone" action="https://urlblabla" method="post">
<!-- // GDPR select -->

<fieldset>
<input type="text" id="userFake2" name="userFake2" value="" autocomplete="off" placeholder="Username">
<input type="hidden" id="user" name="UserName" class="hiddenTwo" value="">
</fieldset>

<fieldset>
<input id="password" name="Password" value="" type="password" autocomplete="off" placeholder="Password">
</fieldset>

</form>
</div>

这是我的代码:

inputuser = driver.find_element_by_id("userFake2")
inputuser.send_keys('email@email.com')
sleep(1);

password = driver.find_element_by_xpath(".//fieldset[.//input[@id='password']]")
password.click()
sleep(1);
password.send_keys('password')

我总是收到错误:

selenium.common.exceptions.ElementNotVisibleException: Message: element not 
visible

回溯:

Traceback (most recent call last):
File "C:\Users\stefa\eclipse-workspace\main.py", line 36, in <module>
password.send_keys('password')
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\stefa\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.ElementNotVisibleException: Message: element not visible
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)

编辑:使用此命令,我可以让光标在密码字段中闪烁:

password = driver.find_element_by_xpath("//*@id='loginNotVodafone']/fieldset[2]").click()
password.send_keys('password')

但收到错误消息:

password.send_keys('password')
AttributeError: 'NoneType' object has no attribute 'send_keys'

最佳答案

xpath 有问题,所以我使用了一个名为 ChroPath for Chrome 的插件,它给了我正确的绝对和相对路径

所以正确的命令是:

password = driver.find_element_by_xpath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[4]/form[1]/fieldset[3]/input[1]").send_keys('password')

或相对 Xpath:

password = driver.find_element_by_xpath("//form[@id='loginNotVodafone']//input[@id='password']").send_keys('password')

关于python - Selenium Python ElementNotVisibleException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51654287/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com