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

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

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

garvitagirotraev
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:


--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/92607220-a118-43ea-875f-c6ad660af6be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

murali krishna-6
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:

<a href="https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;">


--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1e6f8237-9a10-4fb6-b913-5f4a074317f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Evangeline Ireland
In reply to this post by garvitagirotraev
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(...)


On Wednesday, July 5, 2017 at 2:45:34 AM UTC-7, [hidden email] wrote:
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:

<a href="https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;">


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

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

Xiang Dong

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: [hidden email] <[hidden email]> on behalf of Evangeline Ireland <[hidden email]>
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
 
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(...)


On Wednesday, July 5, 2017 at 2:45:34 AM UTC-7, [hidden email] wrote:
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:


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/SINPR03MB2237F286D48587DD770259FF90390%40SINPR03MB2237.apcprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

garvitagirotraev
In reply to this post by murali krishna-6
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.  

On Thursday, November 30, 2017 at 10:32:25 AM UTC+5:30, murali krishna wrote:
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:

<a href="https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG" style="margin-left:1em;margin-right:1em" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;">


--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

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

murali krishna-6
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.

On Wed, Dec 6, 2017 at 4:28 PM, <[hidden email]> wrote:
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.  


On Thursday, November 30, 2017 at 10:32:25 AM UTC+5:30, murali krishna wrote:
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:


--
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 [hidden email].
To post to this group, send email to [hidden email].
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CALJkmZLy-HoGBd-_4xut9nu8FeUL8tkWNg36mD5oVEKe7Pisgw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

garvitagirotraev
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.

On Wednesday, December 6, 2017 at 4:39:49 PM UTC+5:30, murali krishna wrote:
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.

On Wed, Dec 6, 2017 at 4:28 PM, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="wxQV-ntMBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">garvitag...@...> wrote:
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.  


On Thursday, November 30, 2017 at 10:32:25 AM UTC+5:30, murali krishna wrote:
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:

<a href="https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG" style="margin-left:1em;margin-right:1em" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;" onclick="this.href=&#39;https://lh3.googleusercontent.com/-w3NmKKe4jHE/WVy1HM994bI/AAAAAAAAAB4/8FH456EmsnkjIg0-l9mKrPBRSPV6x2xFgCLcBGAs/s1600/html.PNG&#39;;return true;">


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/selenium-users/4Na1GqI6MiI/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/selenium-users/4Na1GqI6MiI/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/selenium-users/4Na1GqI6MiI/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/selenium-users/4Na1GqI6MiI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="wxQV-ntMBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">selenium-user...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="wxQV-ntMBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">seleniu...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/selenium-users/7fabbbf7-067d-43d6-bc3e-b2d2ffede191%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/selenium-users/7fabbbf7-067d-43d6-bc3e-b2d2ffede191%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/selenium-users/7fabbbf7-067d-43d6-bc3e-b2d2ffede191%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/selenium-users/7fabbbf7-067d-43d6-bc3e-b2d2ffede191%40googlegroups.com.

For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.



--
u r friend
           MURALI KRISHNA

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

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

murali krishna-6
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)




On Thu, Dec 7, 2017 at 3:00 PM, <[hidden email]> wrote:
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.

On Wednesday, December 6, 2017 at 4:39:49 PM UTC+5:30, murali krishna wrote:
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.

On Wed, Dec 6, 2017 at 4:28 PM, <[hidden email]> wrote:
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.  


On Thursday, November 30, 2017 at 10:32:25 AM UTC+5:30, murali krishna wrote:
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:


--
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-user...@googlegroups.com.
To post to this group, send email to [hidden email].
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.



--
u r friend
           MURALI KRISHNA

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CALJkmZJWa5vJtvrNmzO7qMrhSAOeydp0xEoG9AGLoBZyzHK5WQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Error msg.PNG (103K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

murali krishna-6
Hi Garvita,

Could you please help me in this?

Thanks,
Murali V.

On Thu, Dec 7, 2017 at 5:53 PM, murali krishna <[hidden email]> wrote:
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)




On Thu, Dec 7, 2017 at 3:00 PM, <[hidden email]> wrote:
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.

On Wednesday, December 6, 2017 at 4:39:49 PM UTC+5:30, murali krishna wrote:
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.

On Wed, Dec 6, 2017 at 4:28 PM, <[hidden email]> wrote:
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.  


On Thursday, November 30, 2017 at 10:32:25 AM UTC+5:30, murali krishna wrote:
The Same problem i am facing in my application as well...Anyone can help me in this?

On Wednesday, 5 July 2017 15:15:34 UTC+5:30, [hidden email] wrote:
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:


--
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-user...@googlegroups.com.
To post to this group, send email to [hidden email].
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.



--
u r friend
           MURALI KRISHNA



--
u r friend
           MURALI KRISHNA

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CALJkmZ%2BcEbhRmH_PriaxmqjCy_e70AObL%2BrAtvOE286Pi8DNkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.