I am new using Phantomjs, and I got the content from a website that I want. Now I want to pass the content into my website (http://test123.com). So what I want to do is, I want to open my website into a new tab in browser. However, I put the code below to test.js file and call it using phantomjs test.js but it didnt work.
var win = window.open("http://test123.com");
Anyone know how can I open a new tab in a browser using phantomjs? what should I put in my .js file ?
Try the following:
var win = window.open("http://test123.com", "_blank");
Related
My problem Statement is:
I want to download PDF using JavaScriptExecutor, When I click on the
PDF link it opens the PDF in a new window, It is an online PDF Viewer window, having a toolbar section where print, download..etc, features are available, Manually I can download by clicking on Download button. Now I want to automate this Scenario, I Researched and found that it can be
handled by using "javascript executor" I inspect that opened PDF window and the toolbar section is inside nested shadow root. Then I proceeded with writing the JSPath of the download element, basically, I copied the JSPath of the download Element, I checked it on the Console and it was able and locate and perform the Click operation. Same when I tried to do it through Script it gives me the exception "Cannot read properties of null(reading 'ShadowRoot')"
Screenshots of DevTool Console
The code I used so far:
IWebDriver driver;
driver.FindElement(By.Xpath("Xpath_of_PDF_Link")).Click();
driver.SwitchTo().Window(driver.WindowHandles.Last());
Thread.Sleep(2000);
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
IWebElement downloadButton = (IWebElement)js.ExecuteScript("return document.querySelector(\"#viewer\").shadowRoot.querySelector(\"#toolbar\").shadowRoot.querySelector(\"#downloads\").shadowRoot.querySelector(\"#download\")");
Thread.Sleep(1000);
var element = "argument[0].click()";
js.ExecuteScript(element,downloadButton);
Screenshots of devTool attached below
Does anyone have any possible solutions or insight into How to download the PDF? I'm relatively new to programming and would appreciate any advice.
Please let me know, If any other information required.. Thanks in advance
You could just get the url of the pdf link, then download it using an HTTP client.
I'm not familiar with C#, but here's pseudocode:
var url = driver.findElement(pdflink).getAttribute(href);
var client = new HttpClient();
var result = client.Get(url);
Files.write("myfile.pdf", pdf);
I have a task that needs to automatically download a file once the user click the button “ok”. I don't have access on the database or source code on the website, just view site access only. I don't know where and how to create it for me to start working on it. I been trying to do it using windows form but I'm not sure if its possible since the application is in the website.
How I can start doing this automatic download without any access on the applications code?
You can use the System.Net.WebClient to download a file from the web.
However you should find a pattern in the file uri.
Here is a sample:
var FileDownload = "http://addressforthefile.pdf";
var FileSaveLocation = #"C:\Downloads\myfile.pdf";
var WebClient = new System.Net.WebClient();
WebClient.DownloadFile(FileDownload, FileSaveLocation);
I'm making a browser extension and I have a credentialManager.html file that I want to open in a new window. Currently doing this
var credentialWindow = window.open("credentialManager.html",
"Credential Manager", "width=150,height=250")
but it just appends credentialManager.html onto whatever website domain I'm on and opens that. I want it to open the file with that name, which is in the extension package. Thoughts?
Found the solution: to access a .html file in the extension package you use the following
var credentialWindow = window.open("ms-browser-extension://[id of extension]/[name of html file].html", "[name your popup window]", "width=[some num],height=[some num]");
I am working on a c# asp.net project in which, I have to print a PDF file from a directory where there are dozens of files.
I can pick the file from directory but I am not able to print that file by generating a pop up.
Does any one knows how to pass that file from back end code to java script so that It can show popup and ask for print?
P.S:I can not post code here due to PHI issue.
Thanks in advance.
open your PDF to window, get that window form Javascript,
call javascript function,
OpenPrintPopUP(){
var display_setting="toolbar=no,location=no,directories=no,menubar=no, scrollbars=no,width=650, height=850, left=100, top=25"
var prntWindow = window.open("","",display_setting);
prntWindow.document.write(printContent);
prntWindow.document.close();
prntWindow.focus();
prntWindow.print();
prntWindow.close();
}
I am building an windows app using Tide SDK. How can I open a local file from my app. For example, I have a pdf file somewhere in my harddisk. I put the link to that file to my app. When I click on the link, I want it to open the pdf file using default programm associated with pdf type file.
If it is not possible then I have one more general question. Is it possible to access local file system by any app that built using html5 and javascript?
we can access local file system in tidesdk application.
See the following code.
var contents;
var file= 'test.txt';
var Dir = Ti.Filesystem.getUserDirectory();
var readfi= Ti.Filesystem.getFile(Dir, file);
if (readfi.exists())
{
var Stream = Ti.Filesystem.getFileStream(readFi);
Stream.open(Ti.Filesystem.MODE_READ);
contents =Stream.read();
alert( contents );
Stream.close();
}
The above code will read the text file and alert the content. Visit here to know tidesdk file system.
Following code will open the given URL in default browser.
Ti.Platform.openURL('http://stackoverflow.com');
Following code will Open the given application or file in the system's default program.
Ti.Platform.openApplication('C:/Documents and Settings/Thavamani00/Desktop/readme.txt');
Ti.Platform.openApplication('C:/Documents and Settings/Thavamani00/Desktop/cart15.png');
The above code displays the text file in notepad and displays the image in mircosoft picture manager.
it works well for me.i hope its your required answer.