IE9 Webdriver NoSuchWindowException - c#

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?

Related

.Displayed in C# throws when browser-testing on Android 8.0.0 via Appium 1.9.1

This code works fine against Chrome in local (i.e. on PC)...
IWebElement widget = Driver.FindElements(widgetLocator).FirstOrDefault(x => x.Displayed);
...but throws the following when used against Appium 1.9.1 to talk to Android 8.0.0:
OpenQA.Selenium.WebDriverException: 'An unknown server-side error occurred while processing the command. Original error: unknown error: Argument to isShown must be of type Element
(Session info: chrome=73.0.3683.90)
(Driver info: chromedriver=2.44.609538
The browser does start up on Android, navigates to the page within our site that it's supposed to, and in most ways works fine. But, Displayed always throws the above without further explanation. Have anyone seen this?
I've tried using ExecuteJavaScript() to check visibility the hard way, but in OpenQA.Selenium ExecuteJavaScript() returns void, not bool as on other platforms. I've tried, Enabled but that doesn't do what I was after. I've borrowed a colleague's IsElementVisible() function as below, but that throws as well:
public static bool IsElementVisible(IWebDriver driver, By locator)
{
WebDriverWait wait = new WebDriverWait(driver,System.TimeSpan.FromMinutes(1));
WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
try
{
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(locator));
}
catch (Exception ex)
{
return false;
}
return true;
}
And finally I've tried to FindElement on the element I'm looking for via CssSelector, ClassName and anything else I could think of, without success (they can't reliably only find the "visible" version of the element).
By way of background, what I'm trying to do here is to "port" some existing test scripts that work against Chrome on PC via WebDriver to test the same website on Android via Appium. This legacy code uses . Displayed in many places and if I can't find a reliable alternative in the mobile situation we'll have somewhat of a problem.
Please find the below code that i have edited
as you can see in your exception it says "Argument to isShown must be of type Element", it means what type of element you are passing please let us know if this solution worked
Exception:
OpenQA.Selenium.WebDriverException: 'An unknown server-side error occurred while processing the command. Original error: unknown error: Argument to isShown must be of type Element (Session info: chrome=73.0.3683.90) (Driver info: chromedriver=2.44.609538
Code Edited:
public static bool IsElementVisible(IWebDriver driver, String locator)
{
WebDriverWait wait = new WebDriverWait(driver,System.TimeSpan.FromMinutes(1));
WebDriverWait w = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
try
{
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.xpath(locator)));
}
catch (Exception ex)
{
ex.printStackTrace();
return false;
}
return true;
}
Upgrading to Appium WebDriver 4.0.0.4beta fixed the problem for me.

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.

Invalid Argument was supplied Exception when running C# test using Selenium WebDriver with Firefox 50.0

I'm learning Selenium WebDriver and trying to run a simple test using Firefox 50 and Webdriver 3.0.1. I'm using Marionette driver 0.11.1
I have the following code:
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"P:\Selenium Practice\FirefoxDriver", "wires.exe");
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
FirefoxOptions options = new FirefoxOptions();
options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
TimeSpan time = TimeSpan.FromSeconds(10);
IWebDriver driver = new FirefoxDriver(service, options, time);
driver.Navigate().GoToUrl("http://www.demoqa.com");
When running it, I'm getting the following exception with error code 10022:
It says:"An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll"
I'm not really getting what I'm doing wrong. I went throw a lot of suggestions and none of those really worked. The last one that I describe here is that one: Setting up Marionette/ GeckoDriver
What can I do to fix it?

Sending keys in selenium

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();

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