I'm not able to launch IE browser to run my selenium automated tests written in C#.
I know the problem is that I don't have the security settings set to the same level.
I also know that the way to fix this normally is to simply select the same security level for all zones in IE security tab. BUT My work has made the security tab unavailable to me. Does anybody know another work around for this issue?
//Start Opening browser
DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
caps.SetCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(caps);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(this.baseURL);
Thank you in advance!
Found a solution. In addition to ignoring protected mode settings I also ignore zoom settings and clicks were not working so I also ignore native events.
Here is the new code:
var options = new InternetExplorerOptions()
{
InitialBrowserUrl = baseURL,
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
IgnoreZoomLevel = true,
EnableNativeEvents = false
};
driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(this.baseURL);
Yes, you can do it using DesiredCapabilities class of selenium WebDriver
// Set capability of IE driver to Ignore all zones browser protected mode settings.
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
// Initialize InternetExplorerDriver Instance using new capability.
WebDriver driver = new InternetExplorerDriver(caps);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
Hope the same code works for you.
Related
Good morning.
I am developing a spider to review a few web pages. I can't do it without using Selenium. But the problem with Selenium is that it consumes a lot of resources and is slow. I am looking for the optimization way.
From what I see the main problem is that Selenium loads the entire website, with all its resources. But I just need javascript and html to work for me. But I don't need images. Can I somehow prevent images from loading in the Selenium browser in C #?
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using (IWebDriver driver = SeleniumUtility.GetChromeDriverHidden())
{
driver.Url = "https://stackoverflow.com/";
string html = driver.PageSource;
}
internal static ChromeDriver GetChromeDriverHidden(bool hidden = true)
{
ChromeDriverService service = ChromeDriverService.CreateDefaultService(".");
service.HideCommandPromptWindow = true; // Hide output commands in console
var options = new ChromeOptions()
{
AcceptInsecureCertificates = true // This lets the browser accept the insecure certificate. Set hidden = false
};
if (hidden)
{
options.AddArgument("headless"); // hide window if added to options
}
return new ChromeDriver(service, options);
}
I see one solution, but in C# I don't understand how to do it.
Try this, I hope it helps
ChromeOptions options = new ChromeOptions();
options.addArguments("headless","--blink-settings=imagesEnabled=false");
Or
IWebDriver driver;
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("profile.default_content_setting_values.images", 2);
driver = new ChromeDriver(options);
See the original answer here
IDE: Visual Studio 2015
Geckodriver.exe (Version 0.19.0) - Published: 9/25/2017
Firefox version: 56.0b8 (64-bit)
Selenium webdriver version: 3.6.0
Using Selenium and C # I did as lines of code below:
using (FirefoxDriver = new FirefoxDriver () driver)
{
driver.Navigate (). GoToUrl("https://www.teste.gov.br/seguro/loginPortal.asp");
Thread.Sleep (1000 * 60);
}
The page opens a message of "Your connection is not private", error "Your connection is not secure".
To resolve this issue you have already used the following codes:
profile = webdriver.FirefoxProfile ()
profile.accept_untrusted_certs = True
driver = new FirefoxDriver (profile)
profile = webdriver.FirefoxProfile ()
profile.accept_untrusted_certs = True
driver = new FirefoxDriver (profile)
profile.setAcceptUntrustedCertificates (true);
profile.setAssumeUntrustedCertificateIssuer (false);
driver = new FirefoxDriver (profile)
ffProfile.setAcceptUntrustedCertificates (true)
ffProfile.setAssumeUntrustedCertificateIssuer (false)
driver = new FirefoxDriver (ffProfile)
and other codes ...
But the problem continues. How to solve this problem?
TL:DR; There is no reasonable approach to solving this problem.
If it's absolutely necessary to visit the site only, e.g. to create a cookie, use PhantomJS. Every browser driver I've tried gives the error, and it's impossible to bypass without some sort of security exploit.
The browser is literally letting you know the site is insecure. Albeit its a government site, it might be compromised.
On a separate note, its probably cleaner to do this:
FirefoxDriver() ffDriver = new FirefoxDriver();
ffDriver.Navigate("myCoolSite.url");
I am facing one issue when tried to maximize the remote chrome browser to a specific size when tests are written in C# running on Selenium Grid.
I tried below options
options.AddArgument("--window-size=1920, 1080");
Driver.Manage().Window.Size = new Size(1920, 1080);
But, the browser does not maximize.
Can anyone please help me?
Try this:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-extensions");
_webDriver = new ChromeDriver("c:\path"), options);
_wait = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(10));
_webDriver.Manage().Window.Maximize();
I am writing a program to run videos listed on my site for testing purpose and here what I need is to run videos in different tabs of the same browser window.
I have hundred video urls in the List videoLinks = getVideoUrls();
and now what I need is to execute these videos 5 at a time.
ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.withoutabox.com" + videoLink);
If I go the above way then for all videos I will have to create a new ChromeDriver object. I want to use single chrome browser object.
I have tried this
IWebElement body = driver.FindElement(By.TagName("body"));
body.SendKeys(Keys.Control + "t");
it only adds a new tab but not open a link there.
Please let me know how should I go around it. I have googled but couldn't find my solution so thought to ask for help.
Try this:
public void SwitchToTab(object pageId)
{
webDriver.SwitchTo().Window(pageId.ToString());
}
You can use CurrentWindowHandle to find current tab.
webDriver.CurrentWindowHandle;
For your scenario I'm using that code:
public IPageAdapter OpenNewTab(string url)
{
var windowHandles = webDriver.WindowHandles;
scriptExecutor.ExecuteScript(string.Format("window.open('{0}', '_blank');", url));
var newWindowHandles = webDriver.WindowHandles;
var openedWindowHandle = newWindowHandles.Except(windowHandles).Single();
webDriver.SwitchTo().Window(openedWindowHandle);
return new SeleniumPage(webDriver);
}
Update
Window open create new popup. By default this option can be blocked by browser settings. Disable popup blocking in your browser manually.
To check this, open js console in your browser and try to execute command window.open('http://facebook.com', '_blank');
If new window open successfully than everythng is OK.
You can also create your chrome driver with specific setting. Here is my code:
var chromeDriverService = ChromeDriverService.CreateDefaultService();
var chromeOptions = new ChromeOptions();
chromeOptions.AddUserProfilePreference("profile.default_content_settings.popups", 0);
return new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromSeconds(150));
Here is a simple solution for open a new tab in seleneium c#:
driver.Url = "http://www.gmail.net";
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.open();");
I've managed to handle a missing security certificate in IE8, however quite often the browser will hang while loading "Downloading picture res://ieframe.dll/background_gradient_red.jpg..." and any following IE tests on the node fail also.
I'm working with the ops team to fix the certificate issue, but in the meantime has anyone else seen this problem?
In case it helps here is how I'm creating the driver...
DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorer();
capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
capabilities.SetCapability(CapabilityType.HandlesAlerts,true);
capabilities.SetCapability("ignoreProtectedModeSettings",true);
driver = new RemoteWebDriver(new Uri(GridHubUrl), capabilities);
driver.Manage().Cookies.DeleteAllCookies();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(60));
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(60));
And this bit handles clicking override...
public static void Handle()
{
if (driver.ToString() == "OpenQA.Selenium.IE.InternetExplorerDriver" ||
driver.Url.Contains("res://ieframe.dll/invalidcert.htm"))
{
try
{
driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");
Today I faced the same issue, but resolved by doing this-
Browser setting:
In your browser go to:
Settings-> Internet Options->Security-> Trusted Sites ->"Sites" button -> Add your site
System.setProperty("webdriver.ie.driver","C:\\Users\\XXXXXX\\Desktop\\selenium jars\\Eclipse Jars\\IEDriverServer_x64_2.29.0\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
driver = new InternetExplorerDriver();
driver.get(baseUrl + "/content/");
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.findElement(By.id("edit-acct")).clear();