python输入隐藏输出隐藏_将值输入到类型=“隐藏”中。使用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.

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:

Email or username

Email or username

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: Message: element not visible

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")

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")

Many thanks for your help.

解决方案

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"]')))

Python,特别是在使用Selenium库进行Web自动化测试时,如果你想模拟用户在输入元素键入字符串"FYCPP_D17"并触发表单,你可以按照以下步骤操作: 首先,你需要安装selenium库,如果你还没有安装,可以使用pip安装: ```bash pip install selenium ``` 然后,你需要初始化一个WebDriver实例,比如使用Chrome浏览器: ```python from selenium import webdriver # 如果需要的话,添加一个等待时间,让页面加载完成 from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) # 设置超时时间 # 要找到表单元素,例如HTML ID、CSS选择器或XPath form_element = wait.until(EC.presence_of_element_located((By.ID, 'your_form_id'))) # 输入机台ID input_field = driver.find_element_by_name('your_input_field_name') or \ driver.find_element_by_id('your_input_field_id') or \ driver.find_element_by_css_selector('#your_input_field_css') input_field.send_keys('FYCPP_D17') # 提交表单,假设有一个submit按钮 submit_button = driver.find_element_by_name('submit') or \ driver.find_element_by_id('submit_button_id') or \ driver.find_element_by_css_selector('#submit_button_css') submit_button.click() ``` 在这个例子,你需要将`'your_form_id'`、`'your_input_field_name'`、`'your_input_field_id'`和`'submit'`等替换为你实际表单和字段的实际标识符。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值