我正在尝试将CSV文件上载到此网站:我尝试通过XPath和Partial_link_text来查找元素,但都不起作用。
下面是我使用的代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.implicitly_wait(0.5)
driver.maximize_window()
driver.get("https://maalaei97-test3.hf.space/?__theme=light")
#to identify element
s = driver.find_element(By.XPATH, "//input[@type='file']")
#file path specified with send_keys
s.send_keys("F:/elmo sanat/thesis/design/pythonProject/df.csv")
这是我收到的错误:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='file']"}
3条答案
按热度按时间zd287kbt1#
您需要等待页面加载完成后再尝试上载文件。
最好的方法是使用
WebDriverWait
expected_conditions
显式等待。下面的代码对我来说工作正常:
brccelvz2#
也许您可以尝试使用CSS选择器而不是XPATH?
试试看:
shyt4zoc3#
将“隐式等待”增加到至少5或10秒。
它会正确上载文件。