Reputation: 255
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:
<div>
<table id="listtable">
</table>
<br/>
<input type="hidden" name="delFiles" id="deletefiles"/>
<table id="filetable">
<tbody>
<tr>
<td>
<input type="file" size="27px" id="page" name="page"/>
</td>
<td>
<a href="#">
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</a>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
<tr>
<td>
<input type="file" size="27px" name="page"/>
</td>
<td>
<img name="del" onclick="removeRow(this);" title="delete" alt="delete" src="images/user_delete.png"/>
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
</div>
Upvotes: 3
Views: 10644
Reputation: 169
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");
Upvotes: 15
Reputation: 140
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)
Upvotes: 0
Reputation: 147
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 :)
Upvotes: -1
Reputation: 5453
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.
Upvotes: 1