I have 30 tests working locally with Selenium C# in headless mode.
The problem occurs, when I try to use Jenkins. The message is "Unable to locate element".
It took lots of time to understand that the problem is not time wait and not frame size.
Chrome options (they say frame size will help, but its not):
ChromeOptions co = new ChromeOptions();
co.AddArgument("--window-size=2560,1440")
co.AddArgument("--ignore-certificate-errors")
co.AddArgument("headless")
Tested web application was made with vue.js (everything is dynamically generated).
To get the page or subpage displayed by URL Jenkins needs about 2-4 seconds:
driver.Url = "http://app.com/home" //not my URL
And every Click() works good on a certain URL: you can click anywhere, even on a pop-up form, if the URL is the same (Click() takes about 600 ms).
But if you Click() on element which directs to another URL, the page is not displayed (even if you wait 80 seconds).
This problem could be solved by using
driver.Url = "http://app.com/home/menu"
but thats not real testing.
Related
I'm using selenium webdriver to handle Chrome browser for long running process, and some times it hangs on opening new url. This occurs randomly as I noticed, when the browser window is not active for long time. As soon as I activated the browser window, the browser resumes and loads the website. I'm using following options to initiate the driver.
ChromeOptions opt = new ChromeOptions();
opt.AddArguments(#"user-data-dir=./chromeprofile");
opt.AddArguments(#"disable-infobars");
opt.AddArguments(#"disable-notifications");
I guess the Chrome is pausing the browser until the user returns to the browser window. I just want to know is there any option to add here, to keep going the process even if the browser window goes inactive for long time. Can anyone point me in right direction to find a way to keep the browser working for long time without focus?
I run multiple (2) IE web-drivers together.(for user side and admin side tests)
When the InternetExplorer WebDriver click on link/button that opens an modal popup, login page are opened on new window (abnormal).
When the ie webdriver popup the window , I can see for a fraction of a second the correct address the browser should load (in URL line) , but immediatly it changed to the login url, and required enter username and password.
I found the same problem in this link,
I made the solution there, but I still have not solved the problem, and I get an entry window instead of the expected window.
see this screenshot
My IE version is 11.
My Selenium.WebDriver is 3.141.0.0
My ie webdriver is IEDriverServer_x64_3.141.5
My InternetExplorerOptions:
private static InternetExplorerOptions ieOptions = new InternetExplorerOptions
{
EnsureCleanSession = true ,
EnableNativeEvents = true ,
RequireWindowFocus = true ,
EnablePersistentHover = true ,
ForceCreateProcessApi = true ,
BrowserCommandLineArguments = "-framemerging -private"
};
I added the registry keys:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FrameMerging\(DWORD)00000000
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\TabProcGrowth\(DWORD)00000000
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplorer.exe\(DWORD)00000000
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplorer.exe\(DWORD)00000000
Edited:
By the Deepak-MSFT references, I understand that the issue caused by more than one IE web-driver instances.
I tried to kill the IE driver also by adding the ConfirmCleanSession = trueoption to the code, and also manually by running of the following statements from the command line (before running the test);
taskkill / F / IM iexplore.exe / T
taskkill / F / IM IEDriverServer.exe / T
But it did not help once I set 2 IE web-drivers to work together.
(When I tried to run the test only on one driver - it worked great!)
I would appreciate help in solving the problem!
This issue is due to a quirk of IE itself and how the driver creates the popup window for the browser.
The workaround is to ensure there are no iexplore.exe processes running when you start the session with the driver.
References:
(1) session cookie lost when click made to a link that opens a window with window.open()
(2) session cookie lost when click made to a link that opens a window with window.open()
My Solution:
Split the test case into two tests:
First Test -
Use the IE web-driver for the first site (in my case - the admin side), and parallel use another web-driver (which does not cause problems like Chrome web-driver) for the second site (in my case - the admin side)
And a second test-
Use the other web-driver above for the first site, and parallel use the IE web-driver for the second site.
So I covered the tests in IE for the two sites.
I am using Selenium in C# on Windows 10. The site under test should challenge with a Windows Security login box in IE, which it does. But the login box appears to block the call.
var home = "https://site.under.test.com/";
driver = new InternetExplorerDriver(AppDomain.CurrentDomain.BaseDirectory);
driver.Url = home;
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(home + "secure/");
//code to handle login box goes here, never gets executed unless the dialog box
//is manually addressed or something times out in GoToURL(),
//and then the dialog box doesn't work.
The login box appears:
Click here for screenie of the login box
But the execution is stalled on the GoToUrl() call:
Click here for screenie of execution
Doesn't matter what code I place after this to handle the popup, execution is blocked until something times out inside GoToUrl().
Is this expected behavior? How does one get around it?
Clarification: The problem is not how to enter data into the popup. It is about the code execution not advancing to the point where I can enter data into the popup without intervention or timeout.
This works on Win8.1, but not on Win10
The Webdriver no longer officially supports Basic Authentication. It has been removed from the Java code and the .Net version works accidentally. From my experience you can expect it to work (for now) on Win7-8.1, but not on Win10
This from Selenium support:
The support of authentication dialogs was removed from the java bindings with this commit.
I am surprised, they are still present in the c# binding, because there is no support for basic authentication in the webdriver specification.
Not sure if you found the answer yet but here is what I found so far.
.GoToUrl waits for the page to load and since the page has not loaded yet, it waits and waits and throws exception.
You can enter the url usign Javascript. Below for is .Net code for it
string script = "window.location = \'" + url + "\'";
((IJavaScriptExecutor)driver).ExecuteScript(script);
You have to manage your own wait after using the above code.
And Selenium still doesnt work with the Windows Security dialog that you see after this (Or, I havent found any info anywhere that shows how to make Selenium work with this dialog)
The best solution I have found so far is to use AutoIT, and use TAB commands within AutoIT to enter username, move to password adn enter password and then do tab tab until you get to submit button and then click on this location. Please comment here if you have found any better solution than this until now
We are doing the Continuous integration using C# selenium for web base application. We have trigger the script from TFS using the test agent. But the build or the execution is getting successful if the browser type is chrome. For the IE bower we are facing the issue. Please help us in resolving this issue.
Note: When we trigger manual execution from server , execution in IE happens successfully.
Below is my Exception screenshot.
enter image description here
Seems it related to the Webdriver.
Just try below things to check if that works for you:
1 .Try the latest IE
2 .Include setting capabilities of the browser when starting it. Try the below settings and see if it works to help it stay focused on the newly opened window.
capabilities = new DesiredCapabilities();
capabilities.setCapability("ignoreProtectedModeSettings", true);
capabilities.setCapability("ie.ensureCleanSession", true);
webDriver = new InternetExplorerDriver(capabilities);
3 .Edit the browser profile and increase timeout to 180 seconds or more from default 60 seconds. Please note that this constructor is available in .Net API only.
For internet explorer driver, you can use below syntax.
driver = new InternetExplorerDriver(#"z:\seleniumc", new InternetExplorerOptions(),TimeSpan.FromMinutes(5));
Refer to Selenium Webdriver for details.
I want to take a screenshot of a webpage using Selenium.
I have notice that the action to take the screenshot require to open the web browser itself.
tried to change webDriver.Navigate().GoToUrl("http://www.google.com"); with webDriver.Url = "http://www.google.com"; but no success,
I even tried to leave it with no url and the browser opened with url of 'data', which now I understand that something else makes the browser to be open.
private void button1_Click(object sender, EventArgs e)
{
var capabilitiesInternet = new
OpenQA.Selenium.Remote.DesiredCapabilities();
capabilitiesInternet.
SetCapability("ignoreProtectedModeSettings", true);
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("http://www.google.com");
Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();
screenshot.SaveAsFile("E:\\ScreenShot.png",
System.Drawing.Imaging.ImageFormat.Png);
webDriver.Quit();
}
No - you need to let the WebDriver request the page, otherwise how can it know what screenshot to produce?
If you're trying to avoid a real, 'slow' browser starting up and opening a window, you should either consider running that browser headlessly, as per:
How do I run Selenium in Xvfb?
Or check out the headless WebKit browser PhantomJS (or maybe SlimerJS), and using almost exactly the same WebDriver API as you have now, ask it to produce your screenshots 'in-memory':
Phantomjs - take screenshot of a web page
Just replace:
WebDriver webDriver = new ChromeDriver();
with:
WebDriver webDriver = new PhantomJSDriver();
(Obviously requires the application to be installed locally)
Edit: Just a note that the typical use-case for this is 'overnight' continuous-integration / continuous-testing when run from headless CI servers. However, it can be very easily added to other work-flows, e.g. for visual regression-testing, and simple one-off checks.
There's multiple ways to go about it:
There is chrome flag --no-startup-window which should open chrome without window. I tried it, and it didn't work, however, you can give it a go.
Use hacks - there is a way to start chrome without you ever seeing it, it works nicely. Just use --window-position=-9999,0, note that, TakeScreenShot() has some weird anomalies in my experience - it focuses the window, it runs out of memory randomly, etc. What I ended up doing is I wrote chrome extension which can take screenshots and return them back to selenium through JS.