Selenium InternetExplorerDriver does not take screenshot with MVC web application - c#

I am using selenium web driver 3.4.0. I have downloaded IEDriver.exe and copied to bin folder. I have an MVC application which will be working on taking the screenshot for given link. The link can be anything for any website. We need to take the screenshot for that webpage and store that into the PDF.
Now, I have created the console application using C# and added WebDriver.dll. The application works fine when console application is called. The screenshot is taken.
When same code is called from the MVC web application, its taking the screenshot for web page but its black. Is there any reason for this?
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
var driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("URL TO BE BROWSED");
var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
screenshot.SaveAsFile("Test.png", ScreenshotImageFormat.Png);
driver.Quit();

Does it open the webpage at all? If not, make sure you have the correct IEDriverServer.exe. Also, if you are calling Selenium from inside the controller, you need to map the output, like screenshot.SaveAsFile(Server.MapPath("Test.png"), ScreenshotImageFormat.Png); but that would mean your MVC Web App is opening a browser window on your server & going to some other website; I don't know if that is what you want or not.

Related

How to open browser for signing in and get contents in C#

I am trying to get strings from HTML using regular expression and it works on local html file. Only thing I need is to login on website using my program to get html from there.
The problem is that I tried logging in using 3 different codes without luck (I FOUND AL 3 CODES HERE). Website is HTTPS and also has no support for Internet Explorer. Don't want to use fiddler or any debugging tool. I don't care for speed, just want simple browser opening, signing in and getting html code from displayed content.
Is there any way to open chrome/mozilla/opera and transfer displayed HTML to my program? Or, if it's impossible, is there any some kind of universal way for signing in?
Is there any way to open chrome/mozilla/opera and transfer displayed HTML to my program?
You could use for example Selenium WebDriver for this. It will allow you to automate button pushing, text inputting etc. on the target web page. I wouldn't call it a "debugging tool", it's more like a testing framework. NuGet has all the packages you need:
Selenium WebDriver
Selenium WebDriver Support Classes
There is a really neat usage sample here:
// Initialize the Chrome Driver
using (var driver = new ChromeDriver())
{
// Go to the home page
driver.Navigate().GoToUrl("https://yourdomainhere.net");
// Get the page elements
var userNameField = driver.FindElementById("username");
var userPasswordField = driver.FindElementById("password");
var loginButton = driver.FindElementByXPath("//input[#value='Login']");
// Type user name and password
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
// and click the login button
loginButton.Click();
// Extract the text and save it into result.txt
var result = driver.FindElementByXPath("//div[#id='case_login']/h3").Text;
File.WriteAllText("result.txt", result);
}
I am trying to get strings from HTML using regular expression
I have small hunch that you.. shouldn't. You can use the driver to extract the data you want from the page.

Selenium web driver in a web application get user inputs

I have a web application hosted on a web server that uses selenium web driver to do some action on web sites and save that response for the user to see at the end.
Right now this works fine, the user uploads the data to search for and the application runs on the server, opening chrome windows to navigate on the sites.
The issue is that , there is a site that need user input to continue. Is there a way to instead of opening the chrome window on the server, I open it on the clients machine? In a way that I could control the flow of this new page, wait for the user to take action, and then continue to perform the automated action.
Any option would be helpful.
Thanks
you can use driver.Navigate().GoToUrl("http://url.here")
Then you can use a something like
WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
if (driver.FindElement(By.CssSelector("selector")).Displayed)
{
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.CssSelector("selector")));
driver.FindElement(By.CssSelector("selector")).SendKeys("text you want entered");
driver.FindElement(By.CssSelector("selector")).Click(); //There are other properties and methods you can access
}

Disable Autocomplete(IE) in VIsual C#?

I have a very simple C#-Form in which there is just a Web browser opening a website. When i execute the code and the browser loads the desired website i always get an warning which looks like this
I do not want to have to touch the website or the browser for it, is there a way to solve this in C#?
I solved it by adding this line:
webBrowser1.ScriptErrorsSuppressed = true;

Inserting text from a C# WinForms application into a web browser textbox

I'm currently working on a WinForms application that I'm hoping will allow users to enter stored passwords into a web browser without a keylogger being able to see the password. I've got the storing part completed, but I can't figure out how to insert the password into a browser without using either the clipboard or .NET's SendKeys class, both of which can be seen by most keyloggers.
I looked into using Windows messages to do this, but, from what I understand, you need to know the hWnd of a control in order to send it a Windows message. Unfortunately, it appears that web browsers do not use hWnds for individual textbox controls.
I know there has to be a way to do this. In Notepad++, for example, you can drag text into a web browser textbox and the text doesn't show up in keyloggers. Same goes for Neo's SafeKeys. Anyone have any ideas on a general approach to doing this? Thanks so much.
What you want is a WebDriver Library. Unfortunately .net does not have plenty of good ones. You can take a look at WatiN or selenium
From what I understand watin isn't supported anymore and is not multi-browser compatible.
Here is an example of what you can do with selenium
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://testing-ground.scraping.pro/login");
var userNameField = driver.FindElementById("usr");
var userPasswordField = driver.FindElementById("pwd");
var loginButton = driver.FindElementByXPath("//input[#value='Login']");
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
loginButton.Click();
}
I image you can link your driver to an existing opened browser
If you are able to run ruby on the computers I would recommend using Watir
and running the ruby script doing the web manipulation from the c# using processes.

Is it possible to open the html page from the silverlight application with the choice of browser?

Is it possible to open an html page from silverlight web application in chrome/firefox ?
Issue is I have 3 broswers installed on my windows pc.
1.IE
2.Chrome
3.Firefox
I would like to open the html page from silverlight web application in Chrome and not in IE.
I am using following code to open the page.
HtmlPage.Window.Navigate(new Uri("Google.com")); // Opens in IE. But I want it to open in Chrome.
Thanks.
I think you can try this approach ..
From silverlight start the process ( the browser you want to open .. here the challenge would be you need to the path where browser is installed. )
Mostly all browsers support command line arguments ( url is one of them )
you may need to combine these both to achieve your requirement.
for step one as example how to start a process you can refer this link #1
for step 2 you can refer this link #2 example mozilla
Use below code to open .html page from silverlight application.
HtmlPage.Window.Navigate(new Uri(Application URL + "../index.html"), "_blank");

Categories

Resources