In my sample web page, there have print option. I need to call that,
<b> Print </b>
because I need to save above page as PDF(My major requirement is to save that page in PDF format). When I try to do it manually following popup window shows.
I need to do it through chrome C# selenium web driver. How can I do it? Please provide me sample code to solve this problem.
You'd use send keys to CTRL+P on the webpage then use driver find element by and then click
Send keys documentation found here:
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys.send?view=netframework-4.7.2
//This should work for clicking the save/print button without seeing your code I cannot test it.
driver.FindElement(By.XPath("//*[#id="button-strip"]/button[1]")).Click();
The print window is os realted component and you cannot automate them with selenium itself. You may need additional library to automate that along with your selenium code.
You are two Nuget package to it. One simply use InputSimulator and do key inputs like
Or
Automate browse window usings AutoITX nuget package.
Related
I am trying to create function that will essentially check if there is any PDF Viewer [Adobe or any other] is installed as Plugin for browser.
For example:
I someone click on link in webpage it will open up the PDF file instead of showing option to download, this means a PDF viewer plugin is present in browser.
I have my help on internet for this but none of them is with C# code.
Most of them is either JavaScript to check the plugins
others are there to check if Adobe PDF viewer is installed on the machine.
As a pure C# solution, I am not sure where you would want to run it, how would you go about using C# on a browser unless you are working server side? you can try the below as soon as you load your browser page and just save the details to the session variable if asp.net, then you always have a reference to the status of weather the plugin is installed or not.
You cant try a few ways to solve the issue, the first and simplest would be to just create a simple object tag
<object width="400" height="400" data="helloworld.pdf">
<p>Browser does not support PDF</p>
</object>
You can render this on a different page and just query if the control comes up or if the Browser does not support PDF message is shown,might as well just hide it, render it and then check it.
Or you could use the NavigatorPlugins that you can go through and find if there is anything related to PDF
You can check a reference to this SO answer
I have been using Selenium along side C# in Visual Studio 2013. I will make a call to:
driver.Navigate().GoToUrl("http://<insert webpage>");
...Which will open whichever WebDriver I choose to use.
From here, I will make calls to links/text boxes/menus as I need to.
However, I was wondering if there is a way to get the information from webpages without having to actually open a browser, and if so, could someone perhaps explain or link me to the right direction? It would save time and speed up a lot of my programs. I know applications can get information remotely without actually opening a browser, I just do not know how the process works or if Selenium alone will give that ability.
I appologize if this is wrong place to ask this question.
It is not clear whether or not you need to work with web page (like click on the links, or edit test), but here are two options:
You can use PhantomJS.It is headless browser and since there will be no UI execution may be faster. There is a selenium driver for it.
You can use Html Agility Pack to parse the page and WebClient to download the page. No selenium is required in that case. Html Agility Pack will allow you to make XPath queries, find objects by class name or ID. But: you won't be able to manipulate with DOM structure as you can do with real browser. It is just to parse and navigate over static html page.
I have to save webpage as image by passing page URL,i have found one solution on this thread Convert webpage to image from ASP.NET[^] but it doesn't give me proper image(e.g. tried URL http://www.bugmuncher.com/).
Also tried HTML to Image in C#[^] but not able to deal with IViewObject interface ,basically not able to add reference to get this interface.
I have to do something like http://www.usersnap.com does.I made it work on FF,Chrome and IE9 by using canvas element which is unfortunately not supported by IE8.
Can i get proper working solution for my need???
i think you mean taking a screenshot.
Here you are a link about it.
Capture screenshot of active window?
But here i found on the site that just you want. Please check it.
Convert webpage to image from ASP.NET
The webpage can be saved as image by 2 methods.
1. Press ctrl+p
2. Select "Send to onenote" in print prompt window.
3. Press ok.
Now the image can be saved from the microsoft office -> microsoft onenotebook and rightclick on your content. save as the image file.
Second method is by using snapshot via snipping tool.
I have a C#.NET Winform Application, using which, printing of bills etc. would be done.
But the printing would be done by users using a DMP printer.
So is it possible to send the print to a DMP printer in winform application. If yes, then how?
Also, i have a DataGridView in a Form. Now I want to Print that table which is displayed in the gridview. How do i do this? Will I have to use Crystal Reports or else?
Well not sure this answers you well but i would use PDF Sharp or Migra doc to genereate pdf file from your data and print from there, this way i would not have to do Printer DMP settings (I guess)
The easiest and quickest solution is to use the Visual Basic PowerPack's PrintForm control (You can use it in C# projects as well).
http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx
Just drag the control on to your form then from code call
printForm1.Print();
This will print whatever is on the form, so just design your report on a form then call that code, and you're done.
look at Print the form (Visual C #) you can also use VB power Pack
u can only do code like in C# to print any document or page.
PrintDialog p1= new PrintDialog ()
p1.ShowDialog();
I would use visual studio's emmbeded control calles "ReportViewer" control.
You can find it under "Reporting" section in the toolbox .
Please note that you need to have an app that target's framwork 3 and above for you to see this control.
In this control you can Print to selected printer , export to pdf,word and excel.
Check it out.
I do know there's already an accepted answer but I wish to add a new link to a youtube tutorial that i found recently. Print receipt
Cheers.
I need to display HTML in my silverlight application and cannot find a way of doing it. I cannot use the web browser control as it needs to be able to run in or out of a browser.
Does anyone know of a good way to do this, because all I can think of doing at the moment is running replace methods on the text to just replace the tags with C# equivalents eg(<br /> to \n).
The way I do it is to check if the application is running inside the browser and change the means of display accordingly. If running inside the browser, I overlay the application with an IFrame, as I describe in this article: http://www.silverlightshow.net/items/Building-a-Silverlight-Line-Of-Business-Application-Part-6.aspx. Otherwise, I use the WebBrowser control. I have a control which does this all for you in the source code that accompanies my book, which is downloadable from the Apress website here: http://www.apress.com/book/downloadfile/4638.
Hope this helps...
Chris
I believe what you are looking for is HTML Bridge.
Edit I'm am actually now unsure if you'll still have access to javascript if you're running this OOB. I'm going to look into this some more and will further update. I'll still leave the answer up though for reference.
Second Edit Here is what I've found. HTML Bridge is disabled when you run silverlight out of browser. This disables access to the HTML DOM as well as Javascript. However, according to a comment on this site:
HTML Bridge is not available when you first install a OOB app. But you CAN force it if you modify the index.html in the folder where the app is installed just adding the enablehtmlaccess parameter.
It works!
You can even create dynamic HTML elements using the well-known methods of the HtmlPage class. You can even open a new browser window with the Navigate() method and its "_blank" parameter.
Keep in mind this information was posted about SL 3. Its possible that this may have changed, but I doubt it. So it seems that what you may want to do is build a script into the startup of your SL app that detects whether or not your app is running out of browser. If it is then you may want to have some script to call that can modify this file for you.
There recently was a similar question.
I posted a link there to an implementation that parses and displays HTML inline in Silverlight. Of course, it will work only with simple HTML, but maybe you can expand it to your needs.