可以使用send_keys方式实现,关键是要找到控件元素,控件元素的标签必须是input
def test_one(self):
self.driver.find_element(By.XPATH,
"//*[@id='app']/div[1]/div[2]/div/div[2]/div[2]/ul/li[4]/div[2]/div[1]").click()
button = self.driver.find_element(By.XPATH, "//*[@id='app']/div[1]/div[2]/div/div[1]/div/ul/li[1]")
print(button.text)
button.click()
upload_btn = self.driver.find_elements(By.XPATH, '//input[@class="inputSize"]')
upload_btn[2].send_keys("/Users/XXXXXXXX/Documents/02_Code/PyDemo/images/1.png")
遇到的坑,保存信息(Message: unknown error: cannot focus element
),就是因为控件元素定位不正确,导致无法send_keys