Uploading file in selenium webdriver to html label (mac) - selenium-webdriver

I'm trying to automate an image upload using selenium webdriver with java. The problem is that rather than the html element of the link to upload being an
, it's a label: (without the spaces in tags so it shows)
< label class="btn btn-default btn-icon btn-blue custom-file-upload ng-binding" for="logo">Select file< /label>
This prevents me from using sendKeys with the absolute path which is usually the simplest method:
#FindBy(xpath="//label[#for='imageUpload']") private WebElement imageUploadLabel;
imageUploadLabel.sendKeys("AbsolutePathHere");
I've tried using robot/action class as well as there are many examples on these forums of that but as soon as the browse file upload window pops up it effectively kills my script. I know the best way to do this would be just to change the html element in the source code but that is not an option, so I'm looking for another way to possibly do it.
I'm using a mac as well so autoit is not an option. I've looked extensively on these forums and others trying to find an alternative but every option I've encountered either uses an input file html element or does not work for me. Let me know if more information is needed. Any ideas would be greatly appreciated. Thanks in advance!

Related

How to handle Windows file upload in .Net core using Selenium?

I am new to the C# world and I want to know how can a Windows file upload form be automated using Selenium in a .Net core project as it doesn't support AutoIt.
Zehra - It really depends on how precise you want to get to mimicking the user functionality. Typically you click a button that opens a windows dialog where you locate the file on your pc/phone. Since this is really not testing the application and is just a Windows function, I just use send keys. If you want to get more precise, you can look at AutoIT but I would suggest just doing send keys.
Set your location for the file.
string filePath = #"C:\MyFiles\Test.jpg";
Then find the path to the input for the file upload.
driver.FindElement(By.XPath("//div[#class='FileUploadInput']")).SendKeys(filePath);
If you have a spinner or a bar for the upload process, I would wait until that element is no longer visible and then proceed.
As an example - go here - https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_fileupload_get
In the example if you look at the "choose file" element, it looks like:
<input type="file" id="myFile">
You would then just do:
string filePath = #"C:\MyFiles\Test.jpg";
driver.FindElement(By.Id("myFile")).SendKeys(filePath);

Image upload with selenium webdriver not working

I am not able to automate image upload with selenium webdriver.
I have tried with AutoIT and Robot class as well , But its not working.
I have also tried with different options suggested on stackoverflow but not working for me...
driver.findElement(By.xpath("//*[#id=\"addSampleImg\"]")).sendKeys("D:\\Test11");
Any other option to resolve?
You should have to include the file name as an argument in sendKeys().
driver.findElement(By.xpath("//*[#id=\"addSampleImg\"]")).sendKeys("D:\Test11\Your file name with extension")
For ex.
driver.findElement(By.xpath("//*[#id=\"addSampleImg\"]")).sendKeys("D:\Test11\Sample.jpeg");
Hope it will work then.

Display ms word file in html using angular

How can I display Microsoft Word file in HTML page using either Angular or JavaScript. Please suggest any libraries which provide this functionality.
No browsers currently have the code necessary to render Word
Documents, and as far as I know, there are no client-side libraries
that currently exist for rendering them either
However, if you only need to display the Word Document, but don't need
to edit it, you can use Google Documents' Viewer via an to
display a remotely hosted .doc/.docx.
<iframe src="http://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>
Example:
jsfidle
However, if you'd rather have native support, in most, if not all browsers, I'd recommend resaving the .doc/.docx as a PDF file Those can also be independently rendered using PDF.js by Mozilla.
Edit:
Huge thanks to fatbotdesigns for posting the Microsoft Office 365 viewer in the comments.
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' width='1366px' height='623px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>
Live Examples:
Google Docs Viewer
Microsoft Office Viewer
So what I found from my research is you can not display a word file using java script or angular, it only opens up a dialog box to download the file.
Here are some links backing my conclusion.
display doc file in HTML link1
display doc file in HTML link2
As an alternate what you can do is convert word file to HTML and preview it in browser. Mammoth.JS is the best option for this.

Wijmo and Dotnetnuke 7. Has anyone tried it? Not working

Has anyone tried using the wijmo widgets in DNN 7.+ ?
For my example I'm trying to use the upload widget.
If I upload to a path on my server and test, it works (As in the dialog appears to choose a file... the popup)
If I load it within a page on the site, the button shows but nothing happens when clicked.
All script files and necessary markup are correct.
No console erros, nothing. Very confusing.
Wijmo widgets work in DNN 7.+.
The “action” option should be changed to the server’s address of upload.ashx file.
Note: the upload sample can’t be opened by file path(d:/……/upload.html), please make sure it is opened on server.
Thanks,
Richa

Issue in clicking on the browse button with selenium in IE

I am Clicking on the browse button in IE using Selenium Webdriver code in an upload file utility by reading the co-ordinates of the browse text. Whlie the code works fine in some machines in IE and firefox both, in yet another machine the same code is working for firefoxx but the browse button becomes unclickable in IE. We checked the settings in internet options, everything looks alike in both machines.
Please let us know if anyone faced any such issue and the resolution that could work.
If there is any other way to upload the file in your app by avoiding the "Browser" button method, then that is always preferred. Some people will use Apache HTTPComponents to do a POST upload to the servlet that the "Browse" button refers to. That is by far the preferred method rather than using WebDriver. The problem with the Browse button is that it opens native OS controls ( in some cases) and the only way you can control those is by using the Sikuli API to click on elements based on finding them with matching screenshots. Also, if you use Sikuli, you can't run multiple browser tests on the same machine since each test will block screen comparisons of another test and that will rule you out of using RemoteWebDriver.

Resources