I am using Windows 10 with IE11 on selenium XUNIT test. Selenium doesn't click at a desired IE element. Can someone suggest a solution please?
We had similar problem back in the day when the change the webdriver for IE, whit this code I can run it only in some computers, because in another's we have a lost of comunication between IE and the driver/code due another problem.
public static IWebDriver ExplorerDriverSetUp()
{
var options = new InternetExplorerOptions();
options.RequireWindowFocus = false;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.IgnoreZoomLevel = true;
options.EnsureCleanSession = true;
options.InitialBrowserUrl = URL;
IWebDriver driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
return driver;
}
Related
ChromeOptions options = new ChromeOptions();
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
chromeDriverService.SuppressInitialDiagnosticInformation = true;
options.AddArgument("--headless");
string downloadPath = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\Downloads";
options.AddUserProfilePreference("download.default_directory", downloadPath);
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
options.AddArgument("--window-size=1920,1080");
For some reason I cannot download files in chrome when running headless in Selenium -
When not running in headless mode there is no issue downloading files.
Selenium Webdriver Chromedriver V110.0.5
According to Selenium dev page: https://www.selenium.dev/blog/2023/headless-is-going-away/
you need to user "--headless=new" from now.
However, I'm still struggling with downloading files, even using this new attribute
My use case was a bit different. However, the below code gave me the intended results.
Refer to the below code :
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", #"C:\Downloads");
options.AddUserProfilePreference("download.prompt_for_download", false);
ChromeDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://example.com/download-file");
IWebElement downloadLink = driver.FindElement(By.Id("download-link"));
downloadLink.Click();
System.Threading.Thread.Sleep(4000); // wait for awhile for 4 seconds
driver.Close();
I am trying to test automate my application website using selenium and C# on Chromium Edge browser (version 83.0.478.45).
Every time the chromium edge driver opens up browser, it displays a pop up for sync as shown in picture below. Is there any way to stop it?
EdgeOptions used:
options.UseChromium = true;
options.AddArguments("disable-infobars");
options.AddUserProfilePreference("disable-popup-blocking", "true");
options.AddArguments("--disable-web-security");
As discussed in the comments, You can try to launch the MS Edge browser using a default profile that can help you to fix this issue.
using OpenQA.Selenium.Edge;
using System.Threading;
namespace ecwebdriver
{
public class edgewebdriver
{
static void Main(string[] args)
{
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.addArguments("user-data-dir=C:\\Users\\username\\AppData\\Local\\Microsoft\\Edge\\User Data");
var msedgedriverDir = #"E:\webdriver";
var driver = new EdgeDriver(msedgedriverDir, edgeOptions);
driver.Navigate().GoToUrl("<website url>");
Thread.Sleep(3000);
driver.Close();
}
}
}
Sample code that modified by op.
var userDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\Edge\\User Data");
i am using selenium C#, i am trying to disable the pop up of "crashed" chrome:
i tried to set the profile preferences, but its seems that the it ain't changing at all, the code:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("exit_type", "Normal");
options.AddUserProfilePreference("exited_cleanly", "true");
IWebDriver driver = new ChromeDriver(options);
i tried to change the value of exit type to none & None, but without any change at the preferences document.
I'm using C# and I've noticed that chrome driver can be closed propery only when we use Close() method followed by Quit() in finally block. No special options required. I think in java it's the same way. This will help to rid of "Restore pages" while launching chrome with the driver
ChromeOptions options = new ChromeOptions();
options.AddArgument(Configure.chromeProfileDir);
options.AddArgument(Configure.chromePath);
ChromeDriver d = null;
try
{
d = new ChromeDriver(options);
d.Navigate().GoToUrl("https://google.com");
// Your operations...
}
catch(Exception e)
{
// Handle your exceptions...
}
finally
{
try
{
d.Close();
d.Quit();
}
catch(Exception e)
{
}
}
I tested the Answer given by #Icy, and it worked for me. what I used was :
prefs = {'exit_type': 'Normal'}
option.add_experimental_option("prefs", {'profile': prefs})
and it is spoken of by https://superuser.com/a/1343331, only issue is with the method listed there, you will need to edit the file manually every time, so this works way better, tested in may 2021. Just couldn't upvote the answer as I have no reputation yet, and it is the last.
Use below code to handle this pop up:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-extensions");
options.AddArguments("--disable-application-cache");
driver = new ChromeDriver(options);
i tried this code in java, it solved my problem :))
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+profilepath);
options.addArguments("--no-startup-window");
// argument "--no-startup-window" make chrome is failed to start -> selenium will quit chrome normaly
//-> start chrome again, it won't show restore page
try {
driver = new ChromeDriver(options);
}catch(Exception ex){
}
options = new ChromeOptions();
options.addArguments("user-data-dir="+profilepath);
driver = new ChromeDriver(options);
Try this code:
prefs = {'exit_type': 'Normal'}
chrome_options.add_experimental_option("prefs", {'profile': prefs})
Trying to run my tests on IE. I need our plugin to be enabled.
Here is my code written in C#
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Accept;
options.IgnoreZoomLevel = true;
options.EnsureCleanSession = true;
options.EnableNativeEvents = true;
driver = new InternetExplorerDriver(options);
If run under Selenium the plugin is seen as inactive and the site asks to download the plugin.
How can I make InternetExplorerDriver enable my plugin?
Is there smth like options.PluginsEnabled = true ???
Any ideas?
Have gone through previous post, but the error I am facing is different.
Trying to open chrome through webdriver using C#.
namespace HelloWorld
{
public class OurFirstTest
{
static void main(String[] args)
{
IWebDriver driver = new ChromeDriver(#"D:\Automation\chromedriver");
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
During build, command prompt opens with message
Starting ChromeDriver <v2.9.248315> on port 9515.
Browser is not opening....
I Edited my code and you can follow it now, I am using this code to run chrome instance in incognito mode.
IWebDriver driver1;
ChromeOptions m_Options = new ChromeOptions();
m_Options.AddArgument("--user-data-dir=C:/Users/dell/AppData/Local/Google/Chrome/User Data/Profile 2");
m_Options.AddArgument("--disable-extensions");
m_Options.AddArgument("--silent");
m_Options.AddArgument("--incognito");
//Adding a Proxy
Proxy proxy = new Proxy();
proxy.HttpProxy = "XXXX.XXX.X.X:XXXX";
m_Options.Proxy = proxy;
driver1 = new ChromeDriver(#"F:\\ChromeDriver\", m_Options);
driver1.Navigate().GoToUrl("https://www.google.com");
Make sure you set up the right path for driver.
You'd better put your chromediver in the same directory with your test's exe file.
And update your chromedriver to the latest version which is 2.10