Is it possible to upload file with selenium through anchor tag?
up vote
0
down vote
favorite
I have an upload file button looks like this: <a href="javascript:void('');"></a>
Trying to upload file through it using sendKeys()
method.
But I get errors cannot focus on element. Is there's a workaround or the way to upload file with <a>
tag?
I use this:
driver.findElementsByXPath("//a[@title='Upload an image']").get(0).sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
Tried also to click()
, to moveToElement(element).build().perform()
to focus on the element.
java selenium selenium-webdriver file-upload anchor
add a comment |
up vote
0
down vote
favorite
I have an upload file button looks like this: <a href="javascript:void('');"></a>
Trying to upload file through it using sendKeys()
method.
But I get errors cannot focus on element. Is there's a workaround or the way to upload file with <a>
tag?
I use this:
driver.findElementsByXPath("//a[@title='Upload an image']").get(0).sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
Tried also to click()
, to moveToElement(element).build().perform()
to focus on the element.
java selenium selenium-webdriver file-upload anchor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an upload file button looks like this: <a href="javascript:void('');"></a>
Trying to upload file through it using sendKeys()
method.
But I get errors cannot focus on element. Is there's a workaround or the way to upload file with <a>
tag?
I use this:
driver.findElementsByXPath("//a[@title='Upload an image']").get(0).sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
Tried also to click()
, to moveToElement(element).build().perform()
to focus on the element.
java selenium selenium-webdriver file-upload anchor
I have an upload file button looks like this: <a href="javascript:void('');"></a>
Trying to upload file through it using sendKeys()
method.
But I get errors cannot focus on element. Is there's a workaround or the way to upload file with <a>
tag?
I use this:
driver.findElementsByXPath("//a[@title='Upload an image']").get(0).sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
Tried also to click()
, to moveToElement(element).build().perform()
to focus on the element.
java selenium selenium-webdriver file-upload anchor
java selenium selenium-webdriver file-upload anchor
edited yesterday
DebanjanB
35.5k73271
35.5k73271
asked Nov 19 at 19:24
user10664410
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
No it won't be possible to upload a file with selenium through <a>
tag.
File uploading is achieved through:
<input>
tags.- These
<input>
tags needs focus before being filled up by any character sequence
On the contrary,
The attributes of an
<a>
tag are are as follows:
charset
: Defines the character encoding of the linked document.
coords
: Specifies the coordinates appropriate to the shape attribute to define a region of an image for image maps
href
: Specifies the URL of a page or the name of the anchor that the link goes to.
hreflang
: Language code of the destination URL.
name
: Marks an area of the page that a link jumps to.
rel
: Describes the relationship between the current document and the destination URI.
rev
: Specifies the relationship between the target URL and the current document.
shape
: Specifies the shape of the image map.
target
: Where to open the target URL.
type
: Specifies the MIME (Multipurpose Internet Mail Extensions) type of the target URL
accesskey
: Access keys (or shortcut keys).
class
: Document wide identifier.
dir
: Specifies the direction of the text.
id
: Document wide identifier.
tabindex
: Helps determine the tabbing order when the user 'tabs' through the elements on the page.
title
: Specifies a title to associate with the element.
style
: Helps to include inline casecadubf style sheet.
lang
: Sets the language code.
The event attributes of an
<a>
tag are are as follows:
onfocus
: Script runs when the element gets focus.
onblur
: Script runs when the element loses focus.
onclick
: Script runs when a mouse click.
ondblclick
: Script runs when a mouse double-click.
onmousedown
: Script runs when mouse button is pressed.
onmouseup
: Script runs when mouse button is released.
onmouseover
: Script runs when mouse pointer moves over an element.
onmousemove
: Script runs when mouse pointer moves.
onmouseout
: Script runs when mouse pointer moves out of an element.
onkeypress
: Script runs when key is pressed and released.
onkeydown
: Script runs when key is pressed.
onkeyup
: Script runs when key is released.
So, ideally the <a>
tags should also be able to receive the focus.
But as you are seeing an error as ...cannot focus on element... it may be due to other factors which is out of scope for this question.
Conclusion
File uploading have to be done through <input>
tags only.
Reference
- Anchors
- HTML A tag
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
add a comment |
up vote
0
down vote
You need to handle input
field of type file
, but not link:
driver.findElementByXPath("//input[@type='file']").sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
No it won't be possible to upload a file with selenium through <a>
tag.
File uploading is achieved through:
<input>
tags.- These
<input>
tags needs focus before being filled up by any character sequence
On the contrary,
The attributes of an
<a>
tag are are as follows:
charset
: Defines the character encoding of the linked document.
coords
: Specifies the coordinates appropriate to the shape attribute to define a region of an image for image maps
href
: Specifies the URL of a page or the name of the anchor that the link goes to.
hreflang
: Language code of the destination URL.
name
: Marks an area of the page that a link jumps to.
rel
: Describes the relationship between the current document and the destination URI.
rev
: Specifies the relationship between the target URL and the current document.
shape
: Specifies the shape of the image map.
target
: Where to open the target URL.
type
: Specifies the MIME (Multipurpose Internet Mail Extensions) type of the target URL
accesskey
: Access keys (or shortcut keys).
class
: Document wide identifier.
dir
: Specifies the direction of the text.
id
: Document wide identifier.
tabindex
: Helps determine the tabbing order when the user 'tabs' through the elements on the page.
title
: Specifies a title to associate with the element.
style
: Helps to include inline casecadubf style sheet.
lang
: Sets the language code.
The event attributes of an
<a>
tag are are as follows:
onfocus
: Script runs when the element gets focus.
onblur
: Script runs when the element loses focus.
onclick
: Script runs when a mouse click.
ondblclick
: Script runs when a mouse double-click.
onmousedown
: Script runs when mouse button is pressed.
onmouseup
: Script runs when mouse button is released.
onmouseover
: Script runs when mouse pointer moves over an element.
onmousemove
: Script runs when mouse pointer moves.
onmouseout
: Script runs when mouse pointer moves out of an element.
onkeypress
: Script runs when key is pressed and released.
onkeydown
: Script runs when key is pressed.
onkeyup
: Script runs when key is released.
So, ideally the <a>
tags should also be able to receive the focus.
But as you are seeing an error as ...cannot focus on element... it may be due to other factors which is out of scope for this question.
Conclusion
File uploading have to be done through <input>
tags only.
Reference
- Anchors
- HTML A tag
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
add a comment |
up vote
0
down vote
accepted
No it won't be possible to upload a file with selenium through <a>
tag.
File uploading is achieved through:
<input>
tags.- These
<input>
tags needs focus before being filled up by any character sequence
On the contrary,
The attributes of an
<a>
tag are are as follows:
charset
: Defines the character encoding of the linked document.
coords
: Specifies the coordinates appropriate to the shape attribute to define a region of an image for image maps
href
: Specifies the URL of a page or the name of the anchor that the link goes to.
hreflang
: Language code of the destination URL.
name
: Marks an area of the page that a link jumps to.
rel
: Describes the relationship between the current document and the destination URI.
rev
: Specifies the relationship between the target URL and the current document.
shape
: Specifies the shape of the image map.
target
: Where to open the target URL.
type
: Specifies the MIME (Multipurpose Internet Mail Extensions) type of the target URL
accesskey
: Access keys (or shortcut keys).
class
: Document wide identifier.
dir
: Specifies the direction of the text.
id
: Document wide identifier.
tabindex
: Helps determine the tabbing order when the user 'tabs' through the elements on the page.
title
: Specifies a title to associate with the element.
style
: Helps to include inline casecadubf style sheet.
lang
: Sets the language code.
The event attributes of an
<a>
tag are are as follows:
onfocus
: Script runs when the element gets focus.
onblur
: Script runs when the element loses focus.
onclick
: Script runs when a mouse click.
ondblclick
: Script runs when a mouse double-click.
onmousedown
: Script runs when mouse button is pressed.
onmouseup
: Script runs when mouse button is released.
onmouseover
: Script runs when mouse pointer moves over an element.
onmousemove
: Script runs when mouse pointer moves.
onmouseout
: Script runs when mouse pointer moves out of an element.
onkeypress
: Script runs when key is pressed and released.
onkeydown
: Script runs when key is pressed.
onkeyup
: Script runs when key is released.
So, ideally the <a>
tags should also be able to receive the focus.
But as you are seeing an error as ...cannot focus on element... it may be due to other factors which is out of scope for this question.
Conclusion
File uploading have to be done through <input>
tags only.
Reference
- Anchors
- HTML A tag
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
No it won't be possible to upload a file with selenium through <a>
tag.
File uploading is achieved through:
<input>
tags.- These
<input>
tags needs focus before being filled up by any character sequence
On the contrary,
The attributes of an
<a>
tag are are as follows:
charset
: Defines the character encoding of the linked document.
coords
: Specifies the coordinates appropriate to the shape attribute to define a region of an image for image maps
href
: Specifies the URL of a page or the name of the anchor that the link goes to.
hreflang
: Language code of the destination URL.
name
: Marks an area of the page that a link jumps to.
rel
: Describes the relationship between the current document and the destination URI.
rev
: Specifies the relationship between the target URL and the current document.
shape
: Specifies the shape of the image map.
target
: Where to open the target URL.
type
: Specifies the MIME (Multipurpose Internet Mail Extensions) type of the target URL
accesskey
: Access keys (or shortcut keys).
class
: Document wide identifier.
dir
: Specifies the direction of the text.
id
: Document wide identifier.
tabindex
: Helps determine the tabbing order when the user 'tabs' through the elements on the page.
title
: Specifies a title to associate with the element.
style
: Helps to include inline casecadubf style sheet.
lang
: Sets the language code.
The event attributes of an
<a>
tag are are as follows:
onfocus
: Script runs when the element gets focus.
onblur
: Script runs when the element loses focus.
onclick
: Script runs when a mouse click.
ondblclick
: Script runs when a mouse double-click.
onmousedown
: Script runs when mouse button is pressed.
onmouseup
: Script runs when mouse button is released.
onmouseover
: Script runs when mouse pointer moves over an element.
onmousemove
: Script runs when mouse pointer moves.
onmouseout
: Script runs when mouse pointer moves out of an element.
onkeypress
: Script runs when key is pressed and released.
onkeydown
: Script runs when key is pressed.
onkeyup
: Script runs when key is released.
So, ideally the <a>
tags should also be able to receive the focus.
But as you are seeing an error as ...cannot focus on element... it may be due to other factors which is out of scope for this question.
Conclusion
File uploading have to be done through <input>
tags only.
Reference
- Anchors
- HTML A tag
No it won't be possible to upload a file with selenium through <a>
tag.
File uploading is achieved through:
<input>
tags.- These
<input>
tags needs focus before being filled up by any character sequence
On the contrary,
The attributes of an
<a>
tag are are as follows:
charset
: Defines the character encoding of the linked document.
coords
: Specifies the coordinates appropriate to the shape attribute to define a region of an image for image maps
href
: Specifies the URL of a page or the name of the anchor that the link goes to.
hreflang
: Language code of the destination URL.
name
: Marks an area of the page that a link jumps to.
rel
: Describes the relationship between the current document and the destination URI.
rev
: Specifies the relationship between the target URL and the current document.
shape
: Specifies the shape of the image map.
target
: Where to open the target URL.
type
: Specifies the MIME (Multipurpose Internet Mail Extensions) type of the target URL
accesskey
: Access keys (or shortcut keys).
class
: Document wide identifier.
dir
: Specifies the direction of the text.
id
: Document wide identifier.
tabindex
: Helps determine the tabbing order when the user 'tabs' through the elements on the page.
title
: Specifies a title to associate with the element.
style
: Helps to include inline casecadubf style sheet.
lang
: Sets the language code.
The event attributes of an
<a>
tag are are as follows:
onfocus
: Script runs when the element gets focus.
onblur
: Script runs when the element loses focus.
onclick
: Script runs when a mouse click.
ondblclick
: Script runs when a mouse double-click.
onmousedown
: Script runs when mouse button is pressed.
onmouseup
: Script runs when mouse button is released.
onmouseover
: Script runs when mouse pointer moves over an element.
onmousemove
: Script runs when mouse pointer moves.
onmouseout
: Script runs when mouse pointer moves out of an element.
onkeypress
: Script runs when key is pressed and released.
onkeydown
: Script runs when key is pressed.
onkeyup
: Script runs when key is released.
So, ideally the <a>
tags should also be able to receive the focus.
But as you are seeing an error as ...cannot focus on element... it may be due to other factors which is out of scope for this question.
Conclusion
File uploading have to be done through <input>
tags only.
Reference
- Anchors
- HTML A tag
edited yesterday
answered Nov 19 at 19:35
DebanjanB
35.5k73271
35.5k73271
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
add a comment |
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
1
1
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
@Maybellene Updated the answer with more details and reference. Upvote the answer if this/any answer is/was helpful to you for the benefit of the future readers.
– DebanjanB
Nov 20 at 3:25
add a comment |
up vote
0
down vote
You need to handle input
field of type file
, but not link:
driver.findElementByXPath("//input[@type='file']").sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
add a comment |
up vote
0
down vote
You need to handle input
field of type file
, but not link:
driver.findElementByXPath("//input[@type='file']").sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
add a comment |
up vote
0
down vote
up vote
0
down vote
You need to handle input
field of type file
, but not link:
driver.findElementByXPath("//input[@type='file']").sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
You need to handle input
field of type file
, but not link:
driver.findElementByXPath("//input[@type='file']").sendKeys(System.getProperty("user.dir") + "filesimage.jpg");
answered Nov 19 at 19:34
Andersson
34.9k103066
34.9k103066
add a comment |
add a comment |
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%2f53381313%2fis-it-possible-to-upload-file-with-selenium-through-anchor-tag%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