首页 > 解决方案 > 在 Python 中单击隐藏的输入 Selenium

问题描述

我正在尝试使用 Python 在 Firefox 中使用 Selenium 自动化登录过程。

这就是登录按钮在 HTML 中的样子:

<td>
  <input name="cmd" value="lg" type="hidden">
  <input src="ok.png" style="border-style: none;" type="image">
</td>

我尝试了以下方法:

loginButton = driver.find_elements_by_xpath("//input[@name='cmd' and @value='lg']")[0]
loginButton.click()

它返回以下异常和一条空消息。

“selenium.common.exceptions.ElementNotInteractableException:消息:”

该方法返回

“消息:元素不可见”

loginButton = driver.find_element_by_name("cmd")
loginButton.send_keys(Keys.RETURN)

你能解释一下我错过了什么吗?

标签: pythonseleniumfirefox

解决方案


如果要单击隐藏旁边的输入,请尝试

loginButton = driver.find_element_by_xpath("//input[@src='ok.png']")
#  loginButton = driver.find_element_by_xpath("//input[@name='cmd' and @value='lg']/following-sibling::input")
loginButton.click()

推荐阅读