将值输入到类型=“隐藏"中.使用Selenium + Python的字段 [英] Entering a value into a type="hidden" field using Selenium + Python

查看:195
本文介绍了将值输入到类型=“隐藏"中.使用Selenium + Python的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找解决方法,但似乎找不到适合我的方法.希望有人能帮忙.

I've been searching for how to solve this but can't seem to find anything that works for me. Hope someone can help.

我在一个使用python和selenium chrome浏览器的网站上,尝试登录具有以下HTML的网站,您可以在其中输入用户名或电子邮件:

I'm on a website using python and selenium chrome browser and trying to log into a website which has the following HTML where you enter the username or email:

<div>
<span class="g-hdn" id="1986367435LabelSpan"><label for="1986367435">Email or username</label></span>
<label for="1986367435">Email or username</label>
</span>
<span>
<input size="40" maxlength="64" name="1986367435" id="1986367435" type="text" autocapitalize="off" autocorrect="off" placeholder="Email or username" class="fld">
</span>
</div>
<input name="runId2" type="hidden" value="AQABAAAAUCjLu3T7Joi/PEg380w56IAM9Zt6nK8i63MlZ+2gBdjoHrnTe3XAyLU4iGu37LvUilofnGbWAcTJFUjq6KhmWxEHtQVaMNfWeeaZUxXe9asa">

我不能使用ID或名称来选择此输入,因为每次输入的数字都不相同,因此我想使用占位符=电子邮件或用户名"来选择输入框.

I can't select this input using the ID or name as the number is different everytime, so I want to select the input box using the placeholder="Email or username".

每次我选择此展示位置并尝试输入一些字符串时,都会收到一条错误消息:

Each time I select this placement and try to enter some string I receive an error saying:

selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见

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

这似乎是因为类型为"hidden".

Which seems to be because of the type="hidden".

关于如何选择此项和输入文字的任何想法?

Any ideas on how to select this and enter text?

我当前正在使用以下代码来选择占位符,这会导致错误:

I am currently using the following code to select the placeholder, which is giving the error:

driver.find_element_by_xpath("//input[@placeholder='Email or username']").send_keys("email")

我确定该元素是否真正隐藏,因为可以使用以下命令选择该元素(一旦ID可用):

I'm sure sure whether the element is really hidden as I can select the element using the following (once the ID is available):

driver.find_element_by_xpath("//*[@id='1986367435']").send_keys("email")

非常感谢您的帮助.

推荐答案

目标输入字段没有type="hidden"属性.页面重定向最初可能不可见,因此您可以尝试使用ExplicitWait解决此问题:

Target input field has no type="hidden" attribute. It might be not visible initially after page redirection, so you can try to use ExplicitWait to solve this issue:

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

WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH,'//input[@placeholder="Email or username"]')))

这篇关于将值输入到类型=“隐藏"中.使用Selenium + Python的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆