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
}
Related
I am having a strange issue where I am unable to log into a site under test with the Selenium WebDriver, but am not having any issues logging in when running the project under test in Visual Studio, or in our QA environment.
I have broken the test down to the most simplistic example, where it allows me to manually enter the username, password, and click the login button while it waits for verification that it has moved on to the next screen (waits for an element on that page).
All that happens when running under Selenium is a page refresh.
The test:
driver.Navigate().GoToUrl(this._baseURL + "Account/Index");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(drv => drv.FindElement(By.Id("element-on-next-page")));
The login button calls the jQuery $.ajax method to POST data to a service, and is correctly going into the success() method. The service returns a redirect URL.
This, in turn, attempts to redirect, which works when working with the site manually, but simply re-loads the login page when under a Selenium test:
window.location.replace(location.origin + result.RedirectTo);
I have verified that the result.RedirectTo is valid when the test is running (it is the page it should be redirecting to for successful login).
Tested with Chrome 71.0.3578.98, Firefox 64.0.2 and IE 11.472.17134.0. It works fine manually in all three.
I am unsure why this behavior is acting differently under automation.
UPDATE: The page it is attempting to redirect to has an [Authorize()] attribute on the controller. Removing this attribute allows the test to pass. The attribute only causes Selenium tests to fail, not manual testing.
have to try to perform login steps manually on the chrome browser launched by Selenium?
I am not sure but sometimes google redirects to authorization page or verify your identity page just to ensure you are not using automation scripts for creating multiple emails signup or scraping any website data.
Just try to run the same scenario manually on the browser launched by selenium.
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.
We have an internal ASp.NET MVC application which receives requests from an external system.The request looks something like this:
http://test.com/abc/showinfo/12345678990
Controller Action
[Route]
public ActionResult Showinfo(string somenumber)
{
if (somenumber.Contains("1234"))
// Launch Chrome Browser
else
// Launch IE Browser
}
I tried with Process.Start(url ), its works fine in my localbox but fails in Dev server.
Is it possible to Launch a browser in end user system? if yes then please let me know the steps.
Is it possible to Launch a browser in end user system?
Yes.
You can use PsExec to do it. But do note that if you impersonate credentials, it will send the password over the network in plain text.
psexec \\marklap c:\thebrowserpath\thebrowser.exe
References:
http://windowsitpro.com/powershell/common-ways-run-programs-remote-computers
http://ss64.com/nt/psexec.html
System.Diagnostics.Process.Start("iexplore.exe", "http://google.com");
You can replace http://google.com with your custom url
I don't know if it is possible with your solution, but I think it would be more sensible to open a browser on the client as reaction to an answer from your service, i.e. the following workflow
The client sends a request to your server
Your server processes the request and constructs and answer. This answer contains the URL and the desired browser
The server sends the answer back to the client
The client receives the answer and checks for the URL and the desired browser
The client starts the desired browser with the URL
Depending on the client system (is it some sort of custom application/service?) opening the a new browser could be quite simple (Process.Start() or similar). If the whole thing runs in a browser, it could also be just opening a new tab (if it's the same browser). Opening an alternative browser may be tricky, but could be possible for instance in Chrome with Native Messaging (https://developer.chrome.com/extensions/nativeMessaging)
I have a secured site from which I need to scrape data from some particular pages. The page should be opened strictly on IE. I opened the login page from selenium and pass the handle to the webdriver. Then the user surfs various pages and pop ups of that website. A timer runs and it is checked whether a particular page is opened or not. That is being checked with following code.
var windowIterator = driver.WindowHandles;
foreach (var windowHandle in windowIterator)
{
popup = driver.SwitchTo().Window(windowHandle);
if (popup.Title == PageTitle) //PageTitle is string value and is saved in App Config
{
doWork = true; //Scraping would be started on this page
break;
}
}
It is working perfectly for other sites in testing environment. In live environment the pop page is displaying with the session expired message and asking for user credentials. Once that is given then it is working fine. The architecture of the website that is being scraped is unknown to me.
Could any body tell me why this is happening and what is the way out.
Possibly its takes too much of the time to scrap the data before page will be updated/changed.
I believe site give to your browser one-session-cookes. Check all of cookies that site gaves you. Possibly this can be resolved by cookies edit via selenium. If not -- you can refresh the page in smaller than life time of cookies and show to the server that "user is here" =)
I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't