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
Related
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.
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 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.
OK, so we have an online downloads store accessed via our software. Recently we've had requests to allow downloads via normal browsers and it's fairly easy just to slap a download page on. The problem is that it would be confusing to people having two download links, one for the software and one for their web browser, so we want to differentiate between the two and only show the relevant download link.
From what I've gathered, the .net WebBrowser component is the same as IE and uses the same User Agent, so we can't use that unless we subclass the WebBrowser in the software to make it use a specific User Agent. It's the more sensible option, but we'd have to roll out another updated version, which is less than ideal.
Are there any other ways to tell if someone's accessing a site via the .net component? My only other alternative is to copy the store to a different address with the different download links and send people there. Again this is doable, but not ideal.
Check if window.external is null. IE implements window.external to have methods like AddSearchProvider where most of time WebBrowser.ObjectForScripting is null.
I'm not sure if there is any better way to do this, but here is one idea... The WebBrowser control has a property Document that gives you access to the DOM object representing the loaded document (after the page is loaded). This object has InvokeScript method that you can use to run some JavaScript in the loaded page.
You could write a simple JavaScript function, say hideWebDownload() that would switch the view to a view used when the application runs locally and invoke it from your WinForms application that hosts the WebBrowser control:
webCtrl.Document.InvokeScript("hideWebDownload");
The default view of the page would show the download link for web and calling this function in the local application would switch the view to local download link.
Have your software pass in an invisible (to the user) value in the querystring of the URL.
Trivial to look if that's present.
I've been struggling to find an exmample of some C# code (I'm using C# Visual Studio 2008 Express) that can programmatically save an entire web page (given a URL) including the images and formatting (e.g. CSS). The intention is that in a subsequent phase I'd ship this off (not sure how yet) so it could be viewed later via a browser.
Is there an example of the most simple approach (leveraging the .NET Framework methods) to save an entire web page? Saving as one page with a subdirectory for images, or otherwise. Basically the same as what you get with browsers when you say "save entire web page".
The simplest way is probably to add a WebBrowser Control to your application and point it at the page you want to save using the Navigate() method.
Then, when the document has loaded, call the ShowSaveAsDialog method. The user can then save the page as a single file, or a file with images in a subdirectory.
[Update]
Having now noticed "programatically" in your question, the above approach is not ideal as it requires either user involvement or delving into the Windows API to send input using SendKeys or similar.
There is nothing built-in to the .NET Framework that does all of what you ask.
So my approach revised would be:
Use System.NET.HttpWebRequest to get the main HTML document as a string or stream (easy).
Load this into a HTMLAgilityPack document where you can now easily query the document to get lists of all image elements, stylesheet links, etc.
Then make a separate web request for each of these files and save them to a subdirectory.
Finally update all relevent links in the main page to point to the items in the subdirectory.
In effect you would be implementing a very simple web browser. You may run into issues with pages that use JavaScript to dynamically alter or request page content, but for most pages this should give acceptable results.
From code Project: ZetaWebSpider
It's definitely not elegant, but you could navigate a System.Windows.Forms.WebBrowser to the URL and then call its ShowSaveAsDiagog() method to save the page.