WebDriver Selenium browse file Java

Can't browse file using webdriver.

driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); driver.findElement(By.id("1434461513889_57_7_input.file")).sendKeys("C:\\PDF_V1_COL88810_6L_Frangipani_TL_Fr_P1211089.pdf");

Have this error:

NoSuchElementException: Unnable to locate element: {"method":"id","selector":"BatchUploadPlugin_57_fileupload"}

HTML code

--------------Solutions-------------

From the screenshot you have given, I can see the concerned element is in an iframe.

(Check the second bar in the developer tools below the bar containing: Inspector, Console,etc. You will note the iframe#iframe_1434526152814_57_7. ).

Hence, you weren't able to send the path to it.

In order to send the path for upload, you need to switch to the frame first and then send the path to the element "Browse" for upload.

For switching frame, you can use the below code (The frame id that I can see from the screenshot, is iframe_1434526152814_57_7 which I can safely presume to be dynamic and can't use as ID of the frame to switch-to. So, I am assuming there is only 1 frame in the page, hence the code.):

driver.switchTo().frame(0);

Then, send the path to the element using the below code:

driver.findElement(By.xpath("//input[@name='userfile']")).sendKeys("C:\\PDF_V1_COL88810_6L_Frangipani_TL_Fr_P1211089.pdf");

Kindly do in below way :

driver.findElement(By.id("1434461513889_57_7_input")).sendKeys("C:\\PDF_V1_COL88810_6L_Frangipani_TL_Fr_P1211089.pdf");

.File element should not be there in id.

I'm not an expert in selenium, but looks like the snippet of the code you have posted is not able to throw this exception. As it searches for BatchUploadPlugin_57_fileupload, which is form id. And your code is searching for an input, which id is 1434461513889_57_7_input.

Also what I've figured out is that driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); may not work as expected for these developers. Try to replace it with Thread.sleep(3000);. I know that thread sleep is not recommended for selenium, but just to test.

Try below code.. you need to pass upload textbox webelement and upload button webelement..

public void UploadFile(By locatorUpload, By locatorButton, String filePath){

driver.findElement(locatorUpload).sendKeys(filePath);
waitForElementClickable(driver, locatorButton, 4);
driver.findElement(locatorButton).click();

}

public void waitForElementClickable(WebDriver driver, By locator, Integer timeoutInSeconds){
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(locator));
}

For Dealing with Native Elements, Why can't you try out Sikuli Integration with Selenium scripts. You can refer to this link for more details. http://selenium-suresh.blogspot.in/2014/01/sikuli-automation-tool-integration-with.html

Category:java Time:2018-12-18 Views:2

Related post

  • Alert handling in Selenium WebDriver (Selenium 2) with Java 2011-11-23

    I want to detect whether an alert is popped up or not. Currently I am using the following code: try { Alert alert = webDriver.switchTo().alert(); // check if alert exists // TODO find better way alert.getText(); // alert handling log().info("Alert de

  • How do I maximize the browser window in Selenium WebDriver (Selenium 2) using C#? 2010-07-06

    Is there a way to maximize the browser window using WebDriver (Selenium 2) with C#? --------------Solutions------------- There's an outstanding issue to add this functionality to WebDriver, which can be tracked here: http://code.google.com/p/selenium

  • How to open Excel File in Browser using java? 2010-11-23

    I want to open an Excel file in browser using java 1.6.if i have changed excel sheet cell value then it will reflect on original excel file... How to do this? If anybody having solution to this, Please guide me to get this. Advance thanks to All, Sar

  • Display xml file in the browser using java 2011-04-15

    I have an xml file in my computer and i want to display this xml in the browser using java. i have a jsp page and when entering this page i want to display xml file in the browser. how can i do this in jsp page with java code. for example, my xml pat

  • How do I run Firebug within Selenium WebDriver (Selenium 2)? 2010-08-06

    What's the best way to activate Firebug in Firefox when running Selenium 2? Edit: Ok, I realize "best" is open to interpretation, but the profile-based solution really used to be a pain with selenium 1.0. So any alternative is considered better until

  • Using Personal SSL certificates with Webdriver (Selenium 2.0) 2011-04-07

    I am testing a website which requires personal SSL certificates in order to do certain things, such as sign-in. I have a Webdriver (Selenium 2.0) test that I have set up with a proxy: Proxy localhostProxy = new Proxy(); localhostProxy.setProxyType(Pr

  • "TypeError: can't convert String into Integer" when trying to CTRL+click or SHIFT+click in watir-webdriver/selenium-webdriver script 2011-10-23

    I am trying to select multiple items in a date picker defined as table, in a cucumber script using watir-webdriver/selenium-webdriver on Chrome browser. The date picker allows Ctrl and Shift as modifiers. This is the code for a cell: <div type="bu

  • How can we open multiple IE instances while testing web appl. with selenium RC and java in eclipse? 2009-03-24

    I am running a test in Selenium RC with Java in Eclipse to browse two URLs. I get two Selenium windows, but testing of both URLs is done by opening one single IE window. How can I make it open the URLs on two different IE browsers and if possible, si

  • Is it possible to do big size image process on applet on browser in java? 2010-02-08

    i want to run the applet on the browser in java.I have to load and manipulate big size images on the applet. whether is it possible or not? can any body give me the resolution for the same. Thanks, Mishal Shah --------------Solutions------------- It

  • Getting the user's default browser in Java 2010-11-08

    I want to know how to get the location of the user's default Internet browser in Java. How can I get this? I would prefer it as a URI to the browser's executable file. Must work cross-platform. --------------Solutions------------- The safest thing yo

  • Connecting to current selenium browser window with session id 2010-12-03

    I am trying to connect to existing browser window from selenium RC. As per Exposing the selenium browser session id, it seems if I get the current session on selenium RC, I could accomplish this. Has anyone tried it before? I'm using Java. ----------

  • How do I set a an option as selected using selenium-webdriver (selenium 2.0) client in ruby 2011-01-12

    I am trying to get familiar with the new ruby selenium-webdriver as it appears more intuitive mostly than the previous version of selenium and the ruby driver that went with it. Also, i had trouble getting the old selenium to work with ruby 1.9.1 in

  • How to resuse selenium test file in another selenium test 2011-07-12

    Is there way where I can use one selenium test file in another test file like an include directive or something? I do not want to create duplicate files, there is only one change I have to make in an existing test file so I thought if there was a way

  • Getting Chrome Browser in java Applications 2011-08-30

    Is there a way to get the Chrome browser inside of java applications similar to the way Awesomium works in C++ and C# applications? --------------Solutions------------- There is currently no way getting the UI portion into a Java. You should consider

  • Watir/Selenium - browser.goto keep getting TimeOut error on Chrome and Firefox 2012-02-16

    Got a very annoying problem with Watir webdriver.. I have debugged a little, and found out I always get TimeOut::Error on a simple @browser.goto line, even I can visually see the page has loaded fully... The scenario is like this: Open a browser, got

  • Firefox WebDriver (Selenium) And Security Warning Popup 2012-04-23

    I'm doing some automated testing using c#, nUnit, Selenium WebDriver & Firefox. I'm running into a problem with the Security Warning Popup: Although this page is encrypted, the information you have entered is to be sent over an unencrypted connec

  • I receive an error related to C:\progam files\.java. 2013-09-04

    some how c:\progam files\.java is knocking me off every thing why? Checked java and java is up todate original title: deleat c::\progam files\.java --------------Solutions------------- Hi, You may try uninstalling java completely from your computer u

  • Is there a way to embed a browser in Java? 2008-09-07

    Is there a way to embed a browser in Java? --------------Solutions------------- Since JavaFX 2.0 you can use now webview I believe JWebPane is going to be the official way to embed a browser into a java app. Its based on the open sourced engine - Web

  • Browse Files Server-side in ASP.NET 2009-01-29

    I'm creating an ASP.NET web application to schedule tasks on our server from a remote location using a .NET Wrapper for Scheduled Tasks. However, I'm stuck. The user needs to be able to browse the file system on the server to retrieve a "file to run"

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.650 (s). 13 q(s)