Multiple files upload in selenium webdiver

后端 未结 4 2055
鱼传尺愫
鱼传尺愫 2021-01-15 23:50

I want to upload 5 files,but my \'file input\' is same name/id,how can i possible to upload five files. My HTML code is:

相关标签:
4条回答
  • 2021-01-16 00:12

    that easy like //input[@type="file"] will point to the first input tag and (//input[@type="file"])[{INDEX}] where INDEX is the number of the of the input tag note: indexing in xpath starts from 1

    OR you can use the

    file_tag_list =driver.find_elements_by_xpath(//input[@type="file"])
    

    function that the python syntax you can find it for different languages just google it. this function will return a list of webdriver element and then you can

    file_tag_list[0].send_keys(filepath)
    file_tag_list[1].send_keys(filepath)
    
    0 讨论(0)
  • 2021-01-16 00:15

    Holy ##### it even works in PHP:

    public function waitForAjax()
    {
        while(true)
        {
            $ajaxIsComplete = array(
                'script' => 'return jQuery.active == 0',
                'args' => array()
            );
            $ajaxIsComplete = $this->execute($ajaxIsComplete);
            if ($ajaxIsComplete) {
                break;
            }
        }
    }
    

    Thank you :)

    0 讨论(0)
  • 2021-01-16 00:20

    This works on Chrome:

    driver.findElement(By.id("input1")).sendKeys("path/to/first/file-001 \n path/to/first/file-002 \n path/to/first/file-003");
    
    0 讨论(0)
  • 2021-01-16 00:28

    You would do so the same as you would if you were only uploading one file.

    driver.findElement(By.id("input1")).sendKeys("path/to/first/file");
    driver.findElement(By.id("input2")).sendKeys("path/to/second/file");
    driver.findElement(By.id("input3")).sendKeys("path/to/third/file");
    driver.findElement(By.id("input4")).sendKeys("path/to/fourth/file");
    driver.findElement(By.id("input5")).sendKeys("path/to/fifth/file");
    driver.findElement(By.id("upload")).click();
    

    Obviously, you'll need to put in your own correct IDs or whatever.

    0 讨论(0)
提交回复
热议问题