Not able to upload file using Action.sendkeys() in selenium 3.3

211 views
Skip to first unread message

garvitag...@gmail.com

unread,
Jul 5, 2017, 5:45:34 AM7/5/17
to Selenium Users
Hi I am using selenium 3.3. I need to upload file . Steps to reproduce 
1. there is input box and select file button. i found path for sleect file and passed filename in sendkeys().
2. It gave me error can not focus the element.
3. I used Actions class to first focus on element then use sendKeys(). Its not giving any error ut file is not uploaded.

Here is code :
WebElement myElement = (new WebDriverWait(driver, 60))
                .until(ExpectedConditions.visibilityOfElementLocated(By
                        .xpath(prop.getProperty("WebElement myElement = (new WebDriverWait(driver, 60))
                .until(ExpectedConditions.visibilityOfElementLocated(By
                        .xpath(prop.getProperty(".//*[@id='patent-upload-container']/span/input"))));

       Actions actions = new Actions(driver);
        actions.moveToElement(myElement);
        /*actions.click();
       
       actions.sendKeys("M:\\codes\\ipd\\apps\\evsd_documents\\tests\\Glucose_sensors_importable_test10.xlsx");
        actions.build().perform();
        System.out.println("uploaded file");"))));


Note : i have commented click because it clicks element and opens window dialog box. Means xpath is correct. I dont know why send keys is not working.  Below is html code for select file:


murali krishna

unread,
Nov 30, 2017, 12:02:25 AM11/30/17
to Selenium Users
The Same problem i am facing in my application as well...Anyone can help me in this?

Evangeline Ireland

unread,
Nov 30, 2017, 1:40:32 PM11/30/17
to Selenium Users
Just curious, why do you have to moveToElement before sendKeys? Usually, once I find the element (and able to click on it) I can sendKeys to it without moving to element. So myElement.sendKeys(...)

Xiang Dong

unread,
Nov 30, 2017, 9:32:13 PM11/30/17
to seleniu...@googlegroups.com

I guess you click the input is not the "file" input element,  it could be the first one under the span <input type="hidden">.   Suppose your real <input type="file"> should be hidden and you can't click it anymore. change the XPATH to the second input and try it.


--david




From: seleniu...@googlegroups.com <seleniu...@googlegroups.com> on behalf of Evangeline Ireland <eire...@concord.org>
Sent: Friday, December 1, 2017 2:40 AM
To: Selenium Users
Subject: [selenium-users] Re: Not able to upload file using Action.sendkeys() in selenium 3.3
 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6b18e4db-3bbc-46d4-858d-61f5ec9dddfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

garvitag...@gmail.com

unread,
Dec 6, 2017, 5:58:45 AM12/6/17
to Selenium Users
Hi Murali,

I was getting this error because developers had used jasny bootstrap in code. Its purpose is to give look good factor to page, but it makes your element hidden. Its visible on screen but findElement does not work as in html there are layers above this element.

This can be fixed using jquery by removing that jasny bootstrap.  

murali krishna

unread,
Dec 6, 2017, 6:09:49 AM12/6/17
to seleniu...@googlegroups.com, garvitag...@gmail.com
Hi Garvita,

Thank you so much for your response..!!

I was communicated with developers for the same..hey are also unable to help me in this scenario and said that we are used Bootstrap script.

Could you please help me how can we proceed with 'jasny bootstrap'?


Thanks in Advance..!!

Best Regards,
MuraliKrishna V.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/4Na1GqI6MiI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7fabbbf7-067d-43d6-bc3e-b2d2ffede191%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
u r friend
           MURALI KRISHNA

garvitag...@gmail.com

unread,
Dec 7, 2017, 4:30:44 AM12/7/17
to Selenium Users
Hi Murali,

Can you try using below:

JavascriptExecutor js1 = (JavascriptExecutor) driver;
        js1.executeScript("$('.fileinput.fileinput-new input:file').appendTo($('.btn.btn-default.btn-file'));");
        js1.executeScript("$('.btn.btn-default.btn-file).remove();");

Idea is to move this input element just below main div so that it can be visible. And then use sendKeys() to send file path.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

murali krishna

unread,
Dec 7, 2017, 7:23:59 AM12/7/17
to seleniu...@googlegroups.com, garvitag...@gmail.com
Hi Garvita,

Thank you so much for your response.

I have tried by using script that you provided...But unable to reproduce the 'Upload' functionality..

The below code snippet that i used in my driver script.

(a) 
executor.executeScript("$('.fileinput.fileinput-new input:file').appendTo($('.btn.btn-default.btn-file'));");
executor.executeScript("$('.btn.btn-default.btn-file').remove();");
driver.findElement(By.cssSelector("#AffidavitFileName")).sendKeys("C:\\Users\\User1\\Desktop\\Testing\\Test.jpg");

(b)
executor.executeScript("$('.fileinput.fileinput-new input:file').appendTo($('.btn.btn-default.btn-file'));");
executor.executeScript("$('.btn.btn-default.btn-file').remove('btn-file');");
WebElement upld = driver.findElement(By.xpath("//*[@id='AffidavitFileName'] "));
upld.sendkeys("C:\\Users\\User1\\Desktop\\Testing\\Test.jpg");

(c)
String imgpath = "C:\\Users\\User1\\Desktop\\Testing\\Test.jpg";
executor.executeScript("$('.fileinput.fileinput-new input:file').appendTo($('.btn.btn-default.btn-file'));");
executor.executeScript("$('.btn.btn-default.btn-file').remove();");
WebElement upld = driver.findElement(By.xpath("//*[@id='AffidavitFileName']"));
upld.sendKeys(imgpath);

(d)
 And i have tried by using different locators like By.name,By.Id, By.classname etc...still i am getting error


Please find the  error message below :

Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 43470
Only local connections are allowed.
Dec 07, 2017 5:38:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='AffidavitFileName']"}
  (Session info: chrome=62.0.3202.94)
  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'

Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.33.506120 (e3e53437346286..., userDataDir: }, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 62.0.3202.94, webStorageEnabled: true}
Session ID: 890ae749d97aa5071c0d0f91d7ee455e
*** Element info: {Using=xpath, value=//*[@id='AffidavitFileName']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:370)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:472)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:362)
at com.TestAscendsup.SupplierReg.main(SupplierReg.java:175)




To unsubscribe from this group and all its topics, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b39884fa-d864-4f9c-9276-e156675892f8%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Error msg.PNG

murali krishna

unread,
Jan 3, 2018, 2:21:49 AM1/3/18
to seleniu...@googlegroups.com, garvitag...@gmail.com
Hi Garvita,

Could you please help me in this?

Thanks,
Murali V.




--
u r friend
           MURALI KRISHNA
Reply all
Reply to author
Forward
0 new messages