【问题标题】:Upload a file with selenium (Python) [duplicate]使用 selenium 上传文件(Python)[重复]
【发布时间】:2020-05-13 19:49:36
【问题描述】:

在 Instagram 上,我使用 Python 和 Selenium 发布图片。

但是,当这个新窗口打开时,我有点迷失:我应该如何转到我要发布的文件的路径并继续?与硒?与其他图书馆?

我阅读了一些回复,但找不到关于这个(看似简单)点的好回复。我不能使用 input/"sendkey" 选项

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver


    【解决方案1】:

    获取照片的本地路径。然后像向上传元素发送密钥一样上传它。

    dv.find_element_by_xpath("XPATH").send_keys(path of photo)
    

    实际使用示例: 获取照片的本地路径

    with os.scandir("./photos") as entries:
        os.chdir("./photos")
        photos = []
        for entry in entries:
            if entry.is_file():
                print(entry)
                photos.append(entry.name)
    

    上传

    # click on element where you have to upload
    dv.find_element_by_xpath("/html/body/div[1]/div/div[1]/header/div/div[1]/div[2]/form/div[1]/span/span/span[2]").click()
    # input file location from local system
    dv.find_element_by_xpath("/html/body/div[5]/div/div/div[1]/div/form[1]/input").send_keys(photo)
    

    【讨论】:

      猜你喜欢
      • 2021-02-08
      • 2022-01-03
      • 2017-10-02
      • 2022-10-16
      • 2020-04-21
      • 2012-01-15
      • 1970-01-01
      • 2018-01-23
      • 2013-05-29
      相关资源
      最近更新 更多