Python 查找输入类型的最后一个“=”;文件";

Python 查找输入类型的最后一个“=”;文件";,python,selenium,xpath,Python,Selenium,Xpath,整个html: 有几个这样的要素: <input type="file" name="images_responsiveimage_related-0-responsive_image" accept="image/*" id="id_images_responsiveimage_related-0-responsive_image"></p> 我没有收到任何TouchElementExce

整个html:

有几个这样的要素:

<input type="file" name="images_responsiveimage_related-0-responsive_image" accept="image/*" id="id_images_responsiveimage_related-0-responsive_image"></p>

我没有收到任何TouchElementException。

您的xpath似乎有误。要获取最后一个输入文件,请尝试使用该选项

(//input[@type='file'])[last()]
理想情况下,您应该等待元素使用webdriverwait

input_element=WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "(//input[@type='file'])[last()]")))
您需要导入以下库

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

input_element=driver。通过_xpath('//input[@type='file']')[-1]查找_elements_试试这个,告诉我它有帮助吗
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC