可以使用send_keys方式实现,关键是要找到控件元素,控件元素的标签必须是input 

Selenium文件上传

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 Selenium文件上传

 

Selenium文件上传

 

相关文章:

  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2021-05-04
  • 2021-06-08
  • 2021-11-19
  • 2021-11-04
  • 2022-03-07
  • 2021-08-01
相关资源
相似解决方案