【问题标题】:Submit button is not working in Python Selenium提交按钮在 Python Selenium 中不起作用
【发布时间】:2021-07-01 19:21:16
【问题描述】:

我没有使用 Selenium 的经验。我已经尝试了几件事来单击表单内的提交按钮,但没有什么对我有用。请帮我解决这个问题。

我发现按钮已启用 (is_enabled()),但未显示 (is_displayed())。

我一一尝试了以下选项。我在评论中添加了该代码的连续结果。

z=driver.find_element_by_xpath("//input[@name='commit']")
z.click() #It is showing error, Message: element not interactable
z.send_keys(Keys.ENTER) #It is showing error, Message: element not interactable
driver.execute_script("arguments[0].click();", z) #Shows no error, but nothing happens
z.submit() #Shows no error, but nothing happens 

我尝试了driver.implicitly_wait(20),但没有运气。 我也尝试了 until 选项,但它给出了错误。

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='commit']"))).submit() #This raises TimeoutException

HTML 代码如下

输入类型=“提交”名称=“提交”值=“计算”class=“btn btn-primary”自动完成=“关闭”数据禁用-带=“计算”

网页链接是:https://proteins.plus/ktypdbdd9c38b7-1738-45fd-a0fb-90ea86f5dd8b 我单击“DoGSiteScorer 绑定站点检测”,然后单击“DoGSiteScorer”按钮。现在我想舔一下不起作用的“计算”按钮。

那我该怎么做呢?

【问题讨论】:

  • z.submit 在 z 是一种形式时有效,是吗?你能显示 HTML 吗?
  • 请显示更多 HTML。另外,如果您可以发送链接。在完成其他操作之前按钮是否不可见,或者您在等待按钮变为可见的原因是什么?
  • 网页链接是:proteins.plus/ktypdbdd9c38b7-1738-45fd-a0fb-90ea86f5dd8b 我点击了“DoGSiteScorer Binding site detection”,然后点击了“DoGSiteScorer”按钮。现在我想舔一下不起作用的“计算”按钮。

标签: python selenium


【解决方案1】:

问题是这样的:

z=driver.find_element_by_xpath("//input[@name='commit']")

返回该页面上的 11 个元素,您不能在 11 个元素上调用 click()

假设你想点击红色的计算按钮,试试这个:

z = driver.find_element_by_xpath("(//input[@name='commit'])[2]")
z.click()

【讨论】:

  • 我没有意识到这一点!它工作得很好。我现在处于下一步。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 2013-04-09
  • 1970-01-01
相关资源
最近更新 更多