Sending keys in selenium - c#

Winform c# selenium webdriver firefox. It gave me error on this section of the code
builder.KeyDown(OpenQA.Selenium.Keys.F4);
Error
An unhandled exception of type 'System.ArgumentException' occurred in WebDriver.dll
Additional information: key must be a modifier key (Keys.Shift, Keys.Control, or Keys.Alt)
Code
Actions builder = new Actions(driver);
builder.KeyDown(OpenQA.Selenium.Keys.Alt);
builder.KeyDown(OpenQA.Selenium.Keys.Control);
builder.KeyDown(OpenQA.Selenium.Keys.F4);
builder.KeyUp(OpenQA.Selenium.Keys.Alt);
builder.KeyUp(OpenQA.Selenium.Keys.F4);
builder.KeyUp(OpenQA.Selenium.Keys.Control).Build().Perform();

I believe you should use SendKeys like this:
builder.KeyDown(OpenQA.Selenium.Keys.Alt);
builder.KeyDown(OpenQA.Selenium.Keys.Control);
builder.SendKeys(OpenQA.Selenium.Keys.F4);

The code in the end should look like this.
using OpenQA.Selenium.Interactions;
Actions builder = new Actions(driver);
builder.KeyDown(Keys.Alt);
builder.KeyDown(Keys.Control);
builder.SendKeys(Keys.F4);
builder.KeyUp(Keys.Alt);
builder.KeyUp(Keys.F4);
I'm not sure what this last line is being used for.
builder.KeyUp(Keys.Control).Build().Perform();

Related

Selenium test fails "Year, Month, and Day parameters describe an un-representable DateTime."

So when I am trying to start the latest Firefox with an extension from the store I run into following issue:
Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll
An exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll but was not handled in user code
Year, Month, and Day parameters describe an un-representable DateTime.
The program '[15388] testhost.x86.exe' has exited with code -1 (0xffffffff).
Am I doing something wrong there?
The problem is happening since firefox version 45 i think.
And yes I am aware that you can use an existing profile, but the performance is going downhill with that approach.
So if there is somebody who could help me out with this then i would be very grateful.
string ex = #"C:\extensions\speaktome#mozilla.com.xpi";
FirefoxOptions option = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(ex);
option.Profile = profile;
WebDriver Driver = new FirefoxDriver(option); Driver.Navigate().GoToUrl("https://www.google.com/");
Expected: Driver starts with extension enabled.
Actual: you get exception about wrong datetime.

Web Driver Element Element is not clickable c#

The first click is throwing the error. This has worked many times before. Now, it's not working. I checked the class names and they are the same.
At the first wait.Until (drv) line it throws the error
" An unhandled exception of type 'System.InvalidOperationException'
occurred in WebDriver.dll Additional information: unknown error:
Element is not clickable at point (-1469, 66)"
System.Threading.Thread.Sleep(7000);
// Now Click Next (Broke here first time)
wait.Until(drv => drv.FindElements(By.ClassName("compareSelectedAddToMyBriefcaseAddToBOMLabels"))[1]).Click();
// Click Next Again
System.Threading.Thread.Sleep(10000);
wait.Until(drv => drv.FindElements(By.ClassName("compareSelectedAddToMyBriefcaseAddToBOMLabels"))[0]).Click();
// Click Continue
System.Threading.Thread.Sleep(10000);
Anyone using ChromeDriver 61+ may run into this error. The recent update of the ChromeDriver V2.32 fixes this issue. I recommend updating your ChromeDriver. This should do the trick.

Getting start with ArangoDB and .Net - Exception thrown by AddConnection()

I am hoping that someone who has worked with ArangoDB and .Net and C# can help me out.
When I call ArangoClient.AddConnection() an exception gets thrown (of type 'System.ArgumentException' occurred in mscorlib.dll). The message is "An item with the same key has already been added."
The call to ArangoClient is: ArangoClient.AddConnection("127.0.0.1", 8529, false, "NancyTest", "NancyTest", "root");
Any ideas?
You most probably already created a connection with specified alias. With a driver version 0.9.0 and higher you can check if the specified alias already exists through ASettings.HasConnection(string alias) static method.

IE9 Webdriver NoSuchWindowException

I have problem with webdriver on IE9 (win7, c#, selenium 2.3). I get NoSuchWindowException exception.
I found that I need to change 'Enable Protected Mode' for all Security Level to the same value. But I don't want to change my settings generally and manually, just programmatically for time of testing. I thought that I've just need to set IntroduceInstabilityByIgnoringProtectedModeSettings to true and it will be working, but it doesn't. My code (these lines work ok):
var option = new InternetExplorerOptions();
option.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
IWebDriver Driver = new InternetExplorerDriver(option);
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.Navigate().GoToUrl(baseUrl);
This cause exception:
Driver.Manage().Window.Maximize();
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Error retrieving window with handle current
also this:
string pageSource = Driver.PageSource;
An exception of type 'OpenQA.Selenium.NoSuchWindowException' occurred in WebDriver.dll but was not handled in user code
Additional information: Unable to get browse
Do you have idea what is going wrong/what can I do to run my test?

Selenium server start within .NET

I'm using Selenium to control Opera within C#. I'm using selenium-server-standalone-2.33.0 .
When i start the server from command line there is no problem . My code work well.
But I need to start the server from C# and I can start it with a bat file execution. I can start the server and create a driver.
(I'm using "java -jar selenium-server-standalone-2.33.0.jar -trustAllSSLCertificates" command to start the server in both cases.)
My problem is:
If the server started from C# code, my code can't find the element and throwing exception: (Driver's page source property contains xxx element.)
My Code which throws the exception:
element = driver.FindElement(By.Id("xxx"));
All properties of the element throw an exception.
I think it's because of the process.start privileges when i start server. I've searched a lot but i couldn't find anything.
Thanks
I can start sever with this command "java -jar selenium-server-standalone-2.33.0.jar -trustAllSSLCertificates" from command line and C# code. Server starting well i can create driver and can see the page source .
IWebDriver driver = new RemoteWebDriver(new System.Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Opera());
driver.Navigate().GoToUrl(url);
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(100));
But when i want to reach WebElement through this code element throws lots of exception ('element.Displayed' threw an exception of type 'System.InvalidOperationException')
IWebElement element; // FindElement(driver, "txtUserName", 100);
element = driver.FindElement(By.Id("txtUserName"));
string name = element.GetAttribute("Name");

Categories

Resources