【问题标题】:I cannot click on a button while automating a web-server using selenium python使用 selenium python 自动化 Web 服务器时,我无法单击按钮
【发布时间】:2020-11-29 01:02:49
【问题描述】:

信息

我想使用 python selenium 自动化网络服务器 http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html

html代码

<input name="fileToUpload" type="file" class="btn btn-default btn-file btn-sm" xpath="1">

代码

from selenium import webdriver
import time
driver = webdriver.Edge(r"C:\Users\Amardeep\Downloads\msedgedriver.exe")
driver.maximize_window()
driver.get("http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html")
time.sleep(2)
button = driver.find_element_by_xpath("//input[@name = 'fileToUpload']").click()

输出错误

selenium.common.exceptions.InvalidArgumentException:消息:无效参数

尝试过的解决方案

我使用不同的 x 路径单击打开一个窗口以上传文件路径的按钮,但按钮不可单击。我使用按名称、类名、css 选择器查找元素,但它也不起作用。我该如何解决这个问题。

【问题讨论】:

  • 感谢@dimay 纠正我的问题。

标签: selenium browser-automation


【解决方案1】:

试试下面的代码——(我用的是Chromedriver,你用的是Edge,所以相应地修改代码)

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

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)

driver.get("http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html")
time.sleep(2)
Upload_btn = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@name='fileToUpload']")))
action.move_to_element(Upload_btn).click().perform()

我可以使用上面的代码点击一个按钮,如果您有任何问题或遇到任何错误消息,请告诉我。

【讨论】:

  • 感谢您的回答。上面的代码运行良好,我可以点击按钮。
  • 如果对您有用,您可以将其标记为答案。
猜你喜欢
  • 2023-04-11
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 1970-01-01
相关资源
最近更新 更多