I am trying to automate a file uploading using webdriver, my HTML is
it is of type file.
using firebug i got the id and it is same for textbox and button.
by using this command getWebDriverObj().findElement(By.id("fileupload")).sendKeys("code.txt"); am unable to fetch the result.
does any one faced this type of situation, if so can you please help me.
Thanks
Raghuram.
Autois Windows specific only.
Here is a more robust solution:
For this you will have find the "id" of the actual input box (where the path of the file is provided) and then use the following command:
driver.findElement(By.id("upload")).sendKeys("/path/to/the/file");
driver.findElement(By.id("upload_button")).click();
If you are using WebDriverBackedSelenium you can use:
selenium.type("locator", "/path/to/the/file");
selenium.click("upload_button");
If previous method is not working
You can try next chain.
1. Call File Select Dialog by click button (use webdriver method click() or javascript "document.getElementById('id').click()"
2. And send control to Autoit (or something another) and AutoIt will work with File Select Dialog (type addres to file, click button)
For example:
var Autoit = new AutoItX3();
const string widowTitle = "File Upload";
Autoit.WinWait(widowTitle, "File &name:", 10);
Autoit.ControlSetText(widowTitle, "", "[CLASS:Edit; INSTANCE:1]", pathToFile);
Autoit.ControlClick(widowTitle, "", "[CLASS:Button; INSTANCE:1]");
Autoit.WinWaitClose(widowTitle, "File &name:", 10);
Setup java and AutoIt http://code.google.com/p/autoitx4java/
Related
I need to upload a document via Selenium WebDriver using Chromedriver. I have tried all the Action class and JavaScript stuff, but those do not work. I am assuming they do not work because those are relying on the button to be an input field, however, the upload button I'm dealing with is not. It's HTML looks like this:
Steps to reproduce:
Go to: https://www.fedex.com/apps/printonline/#!
Click on View Products under Marketing Material
Click on Get Started under Brochure
Click on Use your File to upload the file
Use Your File
I am able to click the use your file button, but I am not sure how I can upload the file.
driver.get("https://www.fedex.com/apps/printonline/#!");
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
//Thread.sleep(6000);
if (driver.findElement(By.xpath("//area[#alt='close']")) != null) {
driver.findElement(By.xpath("//area[#alt='close']")).click();
}
driver.findElement(By.xpath("//a[#title='Marketing Materials']/child::button")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("//a[#title='Get Started - Brochures']")).click();
Thread.sleep(1000);
WebElement element = driver.findElement(By.xpath("//*[#class='btn fxg-btn-orange mycomputer-upload-link']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", element);
Ok so first of all get rid of those Thread.sleep(), use fluent wait with polling time, preferably as a function to locate the elements:
private WebElement waitFor(By locator) {
int timeout = 10;
FluentWait<WebDriver> wait = new FluentWait<>(driver)
.pollingEvery(Duration.ofMillis(200))
.withTimeout(Duration.ofSeconds(timeout))
.ignoring(NoSuchElementException.class);
return wait.until((driver) -> driver.findElement(locator));
}
Then you can click the buttons and upload the file like this:
waitFor(By.cssSelector("button.view-products")).click();
waitFor(By.cssSelector("a.get-started")).click();
waitFor(By.cssSelector("a.get-started")).click();
waitFor(By.cssSelector("input.file-upload")).sendKeys("path_to_my_file");
Notice I am using the input element to upload the file - I am not clicking the a link, as you do not need to do that. Just send the path directly to the input element.
I have a Selenium WebDriver based script to automate file uploading. It uploads list of files one by one. I use AutoIT script to handle dialog window, file chooser window. Parameter $CmdLine[1] contains the path of actual file.
ControlFocus("Open a file","","Edit1")
ControlSetText("Open a file","","Edit1", $CmdLine[1])
ControlClick("Open a file","","Button1")
I execute it from Java code as following:
Runtime.getRuntime().exec(autoITExecutable);
It opens dialog window, so it can't work without focus on browser window.
File upload field works like this demo:
https://encodable.com/uploaddemo/
I ran simple script for the link you gave and it works great
import os
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://encodable.com/uploaddemo/")
driver.find_element_by_name("uploadname1").send_keys(os.getcwd() + "/test.csv")
driver.find_element_by_name("email_address").send_keys("none#getnada.com")
driver.find_element_by_name("first_name").send_keys("Tarun")
driver.find_element_by_id("uploadbutton").click()
Try your code in similar format as shown below and try:
WinWaitActive("File Upload") // enter the title of the pop up
Send("Path of the file to enter") // enter the path of the file to upload
Send("{ENTER}") / press enter
I am able to open new console sub tab by below code with salesforce fourmula field.
HYPERLINK("javascript:if(typeof(srcUp)=='function') {srcUp('/apex/NSTK_SW_PeriodToPeriodFrom?scontrolCaching=1&id="&Id&"&isdtp=vw');}"+ " else {window.location.href='/apex/NSTK_SW_PeriodToPeriodFrom?scontrolCaching=1&id="&Id&"&isdtp=vw'}", "Reimbursement Statement", "_parent" )
but below I want to open below code in new subtab.... This is also a salesforce formula field with id instead of apex page which is the case above. This is opening in new tab of browser instead of console new tab.
HYPERLINK("/00O0j000000FNko?pv0="+Id,"Reimbursement Report","_blank")
Any kind of help is highly appreciated.
try using "_self" in place of "_blank". This will open under same sub tab
I'm following the following kdb+tick demo: DEMO
There does not seem to be any error when I launch run.bat but all the q instances in the different cmd windows seem to be stuck.
Namely, the q) command does not show up, so after the process has displayed the q.q message, the cursor is blinking on an empty line. Therefore, I am unable to execute any queries.
The only window that does show something is ticker.bat which shows (after q.q message):
k){ON!x y}
'<
#
"q"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://ww..
q))
Why can't I use the other processes? How do I resolve this?
That error in ticker.bat is the process attempting to execute an html file as code. Check what arguments are in ticker.bat then check that source file. I think you'll find you've download html instead of the raw text version.
I need to downlond csv file from my application. In my application there is table which contains rows and on right click of that row it display download option , on click on of that download it displays windows popup with open and save button.
To download csv from my application i have written below code but which is not working :(
WebDriver driver;
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "c:\\test");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
profile.setPreference("browser.download.useDownloadDir", false);
profile.setPreference("browser.download.manager.showWhenStarting", false);
driver = new FirefoxDriver(profile);
driver.get("Application link");
// Steps to click on Download file
Please Help.![enter image description here][1]
Try adding
profile.setPreference("browser.download.downloadDir", "c:\\test");
profile.setPreference("browser.download.defaultFolder", "c:\\test");
In addition - csv can come in many content types, not just text/csv..
Try using Firefox addon like HTTP headers to see the exact type the response.