Selenium Webdriver FIle Upload error element ice:inputFile - file

this is my first post and sorry for asking the same question once again. I am stuck with a issue regarding uploading a file in Selenium Web Driver. I have searched a lot in this forum but the solutions are not working for me. The element which is the file Browse button is embedded in the file text area ( i.e. where the path of the file gets printed after the browsing through file browse dialog box), but the upload button is separate.
The entire element code is:
<input class="iceInpFileTxt" type="file" size="35" name="upload">
I am unable to click on the "browse" button using click() method. I have tried using Autoit/Robot also.
The code of the element from JSP page:
<ice:inputFile id="fileUpload" width="600" autoUpload="true"
value="#{practitionerLoadDataBean.inputFile}"
actionListener="#{practitionerLoadControllerBean.browse}"/>
I know the input type is file so sendkeys() should work. The codes I have been trying are:
WebElement elem = driver.findElement(By.xpath("//input[#name='upload']"));
elem.sendKeys("<PATH>");
The error message shows as:
org.openqa.selenium.remote.ErrorHandler$UnknownServerException:Unable to locate element: {"method":"xpath","selector":"//input[#name='upload']"}
Please let me know where I my mistake is. Thanks in advance.

If the element was simply invisible, it would have been found, but you wouldn't be able to interact with it. The usual solution is to look around for frames.
You can't search for elements contained in frames, you have to switch your driver's context to that frame first.
driver.switchTo().frame("frameName");
Then you'll be able to find the element and upload the file the usual way (please, use the sendKeys() method describes by other answers in here).

Please confirm that the input element is visible
Do not click on the browse button, it will open an system level dialogue box to upload the file & Its very tedious to handle this in selenium.
you can use the following method:
driver.find_element(:id,'videoupload').send_keys("E:\\video.flv")
Please check the "\\" in your code.
Please Keep in mind that the upload will work only If the element you send a file should be in the form
Hope this will work for you.
Cheers!!

File Upload Using SendKeys
FirefoxDriver driver = new FirefoxDriver();
driver.get("URl");
File file=null;
try
{
file=new File("file path");
}
catch(Exception e)
{
e.printStackTrace();
}
Assert.assertTrue(file.exists());
WebElement browserButton=driver.findElement(By.id("button Id"));
browserButton.sendkeys(file.getAbsolutePath());

Try this code:
driver.FindElement(By.XPath("/html/body/div[2]/div[5]/div/div/div/div[2]/div[2]/div[1]/div/div[1]")).click();

Related

how to find the Xpath for below given check box

enter image description here
Please tell me how to get the xpath for check box.
If you are using Chrome browser - one easy way you can use:
Open the Inspect (or just click the F12 key)
Mark the element you need and right click on it (or just right click on the object (the check box) you are looking for)
Choose Copy ---> Copy Xpath
I think the tshirt option is not public yet, did not get it in your site.I tried with shirts, looks like same dev pattern to me, let me know if the solution does not work.
<input id="Classic" class="facetChkBox" type="checkbox" value="brickstyletype:Classic" name=""/>
<label for="Classic"/>
This is the background html code.
As you already know, this is not the classic checkbox html code, so we need to create a xpath for this as shown below
driver.findElement(By.xpath(".//label[#for='Classic']"))
from the point of code reusablity I would suggest a method like this:
public void clickOnCheckbox(String checkbox){
driver.findElement(By.xpath(".//label[#for='"+checkbox+"']")).click();
}
and call it using
clickOnCheckbox("Blousons");
In this way you can use the same code to click on different check boxes, and create a clean code.
to relate more to what I am saying you can go the url
https://www.ajio.com/women-shirts/c/830316016

Selenium script for click the search box in office 365 webmail

when clicking the search field in office 365 webmail the xpath is
.//*#id='primaryContainer']/div[4]/div/div[1]/div[2]/div[1]/div[1]/div/div/div[1]/div[1]/div[1]/div[2]/div[2]/button
but selenium identifies for the first time and not for the second time.
is there any way to write selenium script using
<span class="_n_t ms-font-weight-semilight ms-font-color-neutralPrimary">Search Mail and People</span>
or any way to identify?
You can try finding it by the text it has.
//span[text() = 'Search Mail and People']
Try to use CSS Selector with #FindBy annotation instead of XPATH like:
#FindBy(css="[class='login_textfield textfield required email field normaltext']")
WebElement emailField;
Sorry, I'm not registered, so I cannot provide you deeper example, hope it helps you enough :)
See at:
http://screencast.com/t/rqa9dOoy9iq
Edit:
I saw that you uploaded some source, try:
#FindBy(css="[class='_n_t ms-font-weight-semilight ms-font-color-neutralPrimary']")
WebElement someWebElementVariable;

How to upload multiple files on single statement in selenium?

I am not getting any warning or error message while executing the program.
wd.findElement(By.xpath("XPATH")).sendKeys("ABC.jpg","XYZ.jpg");
But no file is uploading.
wd.findElement(By.xpath("XPATH")).sendKeys("can we make CTRL+A operation" );
Thanks in advance.
I think you may be going about this while "file upload in Selenium" thing wrong, so that's what I'm going to address.
This article by SauceLabs covers the basic steps to handle a file upload through Selenium in both Java and Ruby. Assuming you're using Java, there are a few steps you'd need:
Set the FileDetector method for your WebDriver
Get a WebElement pointing to a valid HTML input tag of type file
Have Selenium type in the file's path (Not sure if this requires absolute paths, but it's probably a good idea)
Submit the form
The following code listing demonstrates how to perform each of these steps:
wd.setFileDetector(new LocalFileDetector());
// point your webdriver to the page containing the upload form.
WebElement upload = wd.findElement(By.xpath("XPATH")); // TODO replace xpath!
upload.sendKeys("/path/to/ABC.jpg");
upload.submit(); // NOTE: Submits the form *containing* the upload field!
Because you've set the file detection method to LocalFileDetection, Selenium will be able to find the appropriate file. If this is not set, then Selenium defaults to the UselessFileDetection implementation, which fails every time to avoid accidental file uploads.
Caveat: If you're using a Javascript or Flash-based multiple file upload system, then this probably won't work, since those typically bypass the original input field or handle upload independently from the form's submission.
You are not getting an error because sendKeys() accepts an array of CharSequence objects. and you are conforming to that method contract
But no file is uploading
That is because the way your code is written now, will actually send the text: ABC.jpgXYZ.jpg.

ArcGIS Javascript Web Map Printout with Popup Shown

I have a working printing task that will simply use the ESRI Print Task to export to PDF like in this sample - https://developers.arcgis.com/javascript/jssamples/widget_print_webmap.html.
However, I was wondering if there is a way to include popups on the printout if the user has clicked on a feature and is displaying the popup at the time of printing. I have not seen anyone asking the same question unfortunately and would like to have this feature on my print task. Does anyone know if this is possible?
I have solved my problem by using a customTextElement and the following code to pick up when the infoWindow selection changes:
dojoOn(map.infoWindow, "selection-change", function(){
//build custom text here
}

Selenium WebDriver cannot locate element within an iframe, and throws NoSuchElementException

I realise there are several queries on here for this same problem but none of them provide a solution to my particular problem.
I am running a web driver test that tries to fill out a form for a mail website to find postcodes based on address details. I keep getting this error when trying to locate the first text box:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":"#ctl00_BodyContent_txtBuildingNumber"}
I have used xpath and the id to try and locate the element but I keep getting the error. I can see that this element is present when the webdriver is running and I have been able to locate another text element on the page and enter text, but I keep getting this error for this field and other fields within the frame.
I am guessing that the problem must be to do with the fact that this field is part of an iFrame.
I have used implicit waits within the test but with no success. I still get the error.
By the sounds of it you'll need to first switch to the iframe element that contains the element that you want to interact with. (Although without seeing the relevant HTML this is a bit of an extrapolated guess).
driver.switchTo().frame();
eg:
driver.switchTo().frame(1);
driver.switchTo().frame(driver.findElement(By.id("id")));
When you've finished interacting with the elements within the frame, you'll need to switch back to the main webpage.
driver.switchTo().defaultContent();
Check your xpath .
try to use simple
driver.switchTo().frame(1);
with wait statement.
sorry a little correction the following worked for me
driver.switchTo().frame(driver.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button i was trying to click was located. (driver is of type WebDriver i.e WebDriver driver ) thank you
The following worked for me
driver.switchTo().frame(myd.findElement(By.xpath("//*[#id='page-15']/div/p/iframe")));
//*[#id='page-15']/div/p/iframe is the xpath of the frame in which the button I was trying to click.(driver is of type WebDriver i.e WebDriver driver)
thank you
you can use wait statement and after using the wait statement use simply
driver.swithcTo().frame();

Resources