How to upload a file in Selenium WebDriver with no 'input' element
up vote
3
down vote
favorite
I have a HTML page with button named "Upload" and id: btn-import-questions
. The element:
<button class="btn btn-success btn-sm col-lg-11" id="btn-import-questions" data-ts-file-selector="questions-import-init"> Upload <i class="fa fa-upload"></i></button>
I tried a Selenium Java code like this:
driver.findElement(By.id("btn-import-questions")).sendkeys("C:/path/to/file.xlsx");
But since this is an upload button and not an input-type element, the above code is not working.
java selenium testing selenium-webdriver automation
|
show 3 more comments
up vote
3
down vote
favorite
I have a HTML page with button named "Upload" and id: btn-import-questions
. The element:
<button class="btn btn-success btn-sm col-lg-11" id="btn-import-questions" data-ts-file-selector="questions-import-init"> Upload <i class="fa fa-upload"></i></button>
I tried a Selenium Java code like this:
driver.findElement(By.id("btn-import-questions")).sendkeys("C:/path/to/file.xlsx");
But since this is an upload button and not an input-type element, the above code is not working.
java selenium testing selenium-webdriver automation
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46
|
show 3 more comments
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have a HTML page with button named "Upload" and id: btn-import-questions
. The element:
<button class="btn btn-success btn-sm col-lg-11" id="btn-import-questions" data-ts-file-selector="questions-import-init"> Upload <i class="fa fa-upload"></i></button>
I tried a Selenium Java code like this:
driver.findElement(By.id("btn-import-questions")).sendkeys("C:/path/to/file.xlsx");
But since this is an upload button and not an input-type element, the above code is not working.
java selenium testing selenium-webdriver automation
I have a HTML page with button named "Upload" and id: btn-import-questions
. The element:
<button class="btn btn-success btn-sm col-lg-11" id="btn-import-questions" data-ts-file-selector="questions-import-init"> Upload <i class="fa fa-upload"></i></button>
I tried a Selenium Java code like this:
driver.findElement(By.id("btn-import-questions")).sendkeys("C:/path/to/file.xlsx");
But since this is an upload button and not an input-type element, the above code is not working.
java selenium testing selenium-webdriver automation
java selenium testing selenium-webdriver automation
edited Sep 26 '17 at 10:47
Ripon Al Wasim
25.4k31124150
25.4k31124150
asked Jul 17 '15 at 6:12
Thirunavukarasu Paramasivam
7619
7619
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46
|
show 3 more comments
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46
|
show 3 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
You are doing it almost correctly, except that sendKeys()
should be called on the input with type="file"
that is, most likely invisible in your case. If this is the case, make the element visible first:
- Selenium Webdriver - click on hidden elements
add a comment |
up vote
1
down vote
Check the DOM because somewhere there must be an <input type="file">
. The website's javascript will call the .click() of this element to pop up the file selector dialog and closing the dialog with a selection will provide the path. With Selenium the same can be achieved with the .sendkeys():
driver.findElement(By.xpath("//input[@type="file"]")).sendkeys(localFilePath);
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You are doing it almost correctly, except that sendKeys()
should be called on the input with type="file"
that is, most likely invisible in your case. If this is the case, make the element visible first:
- Selenium Webdriver - click on hidden elements
add a comment |
up vote
1
down vote
You are doing it almost correctly, except that sendKeys()
should be called on the input with type="file"
that is, most likely invisible in your case. If this is the case, make the element visible first:
- Selenium Webdriver - click on hidden elements
add a comment |
up vote
1
down vote
up vote
1
down vote
You are doing it almost correctly, except that sendKeys()
should be called on the input with type="file"
that is, most likely invisible in your case. If this is the case, make the element visible first:
- Selenium Webdriver - click on hidden elements
You are doing it almost correctly, except that sendKeys()
should be called on the input with type="file"
that is, most likely invisible in your case. If this is the case, make the element visible first:
- Selenium Webdriver - click on hidden elements
edited May 23 '17 at 12:09
Community♦
11
11
answered Jul 17 '15 at 12:16
alecxe
318k63606831
318k63606831
add a comment |
add a comment |
up vote
1
down vote
Check the DOM because somewhere there must be an <input type="file">
. The website's javascript will call the .click() of this element to pop up the file selector dialog and closing the dialog with a selection will provide the path. With Selenium the same can be achieved with the .sendkeys():
driver.findElement(By.xpath("//input[@type="file"]")).sendkeys(localFilePath);
add a comment |
up vote
1
down vote
Check the DOM because somewhere there must be an <input type="file">
. The website's javascript will call the .click() of this element to pop up the file selector dialog and closing the dialog with a selection will provide the path. With Selenium the same can be achieved with the .sendkeys():
driver.findElement(By.xpath("//input[@type="file"]")).sendkeys(localFilePath);
add a comment |
up vote
1
down vote
up vote
1
down vote
Check the DOM because somewhere there must be an <input type="file">
. The website's javascript will call the .click() of this element to pop up the file selector dialog and closing the dialog with a selection will provide the path. With Selenium the same can be achieved with the .sendkeys():
driver.findElement(By.xpath("//input[@type="file"]")).sendkeys(localFilePath);
Check the DOM because somewhere there must be an <input type="file">
. The website's javascript will call the .click() of this element to pop up the file selector dialog and closing the dialog with a selection will provide the path. With Selenium the same can be achieved with the .sendkeys():
driver.findElement(By.xpath("//input[@type="file"]")).sendkeys(localFilePath);
edited Nov 15 at 13:53
answered Nov 15 at 13:26
Visko
73118
73118
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31469386%2fhow-to-upload-a-file-in-selenium-webdriver-with-no-input-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What happens when you click this button manually?
– Eugene S
Jul 17 '15 at 6:24
Window popup will appear immediately and asking for the file path with open and cancel button
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:28
And when you choose a file using this pop up window, will the name of this file appear somewhere on the page after the pop up disappears?
– Eugene S
Jul 17 '15 at 6:30
After providing the file path and click on open, suddenly the popup window disappears and the data in the file are imported to my application.
– Thirunavukarasu Paramasivam
Jul 17 '15 at 6:34
Is your window showing uploaded file path..?? Once check it directly on website.
– Saritha G
Jul 17 '15 at 6:46