Selenium Internet Explorer WebDriver NoSuchElement Exception - c#

New to Selenium WebDriver, trying to get my firefox/chrome scripts working in IE, but it can't seem to locate any element.
For example here's the code I use to start the IE webdriver go to google and search the world 'blah'
driver = new InternetExplorerDriver(#"C:\Program Files (x86)\IEdriver");
driver.Navigate().GoToUrl("http://www.google.com");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
IWebElement search = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.Name("q"));
});
search.SendKeys("Blah");
Result: Google loads then test fails with a 'NoSuchElementException' - Unable to find element with the name==q
this works fine in firefox and Chrome.
*Using Visual Studio Ultimate C# and NUnit
Thanks,
Liz

Related

Selenium ChromeDriver C# - How to send a shortcut browser

How can I send a Chrome shortcut with Selenium ?
I mean shortcuts like Ctrl+S, Ctrl+T or Ctrl+P which has nothing to do with WebElements. I read a lot of similar questions there, but none of the suggested solutions work for me.
Let's say I want to open a new tab (Ctrl+T) on the browser, I tried all the following code without success:
The "standard" way :
IWebElement body = myDriver.FindElement(By.TagName("body"));
body.SendKeys(Keys.Control + "t");
The action way :
Actions action = new Actions(myDriver);
action.SendKeys(Keys.Control + "t").Build().Perform();
The ChromeDriver way 1 :
if(myDriver is ChromeDriver)
{
ChromeDriver chromeDriver = myDriver as ChromeDriver;
chromeDriver.Keyboard.SendKeys(Keys.Control + "t");
}
The ChromeDriver way 2 :
ChromeDriver chromeDriver = myDriver as ChromeDriver;
chromeDriver.Keyboard.PressKey(Keys.Control);
chromeDriver.Keyboard.PressKey("t");
chromeDriver.Keyboard.ReleaseKey(Keys.Control);
chromeDriver.Keyboard.ReleaseKey("t");
Notice that the first way i mentionned worked for me with other WebDriver than Chrome.
I use :
Selenium 3.0.1
ChromeDriver 2.27.440174
And my driver's initialization is really basic :
ChromeOptions options = new ChromeOptions();
this.myDriver = new ChromeDriver(/* my path */, options);
Any ideas?
It seem to be Chromium issue. You cannot use keys combinations with chromedriver, but you still can use JavaScript as alternative:
IJavaScriptExecutor js = myDriver as IJavaScriptExecutor;
js.ExecuteScript("window.open()"); // Open new browser tab like `CTRL + t` do
Unfortunately this issue currently prevents chrome from reacting to shortcuts like Ctrl+T sent by selenium.
I'm using key combinations with Actions just fine. I have been using this code example for years and it works with Chrome, Firefox, and IE.
public void SelectAll()
{
(new Actions(yourDriverInstance)).SendKeys(Keys.Control).SendKeys("a").Perform();
}
Am I missing something???

Why I cannot use LINQ and IJavaScriptExecutor in Selenium 3.0 and how to solve it?

I use the following specs for my testing:
Mozilla Firefox 46.1
Selenium WebDriver 2.53.1 via Nuget
Windows 10 64bit
Here is my code
using (IWebDriver driver = new FirefoxDriver())
{
driver.Navigate().GoToUrl("someURL");
//error
var e_email = driver.FindElements(By.TagName("input"))
.Where(x => x.GetAttribute("name") == "email"
&& x.GetAttribute("Placeholder") == "Guest Email").FirstOrDefault();
//also error
string js = "var paras = document.getElementsByClassName('someClass');for(var i=0;i<paras.length;i++) {{ paras[i].parentNode.removeChild(paras[i]);}}";
((IJavaScriptExecutor)driver).ExecuteScript(js);
}
The above code runs well in Mozilla Firefox 46.1 and Selenium 2.53.1. The errors appear when I update the Selenium to ver 3.0 and Mozilla Firefox to ver 47 with geckodriver 0.11.1
It generates error : Permission denied to access property 'navigator' for the LINQ and Permission denied to access property 'document' for the IJavaScriptExecutor when executed after being updated to newer version. Why should it happen and how to solve this issue?
I was having a similar issue waiting for a fairly complicated XPath in a WebDriverWait and what ended up fixing it was updating Firefox to 49.0.2.

Selenium FindElement working for Firefox but not for IE

So I am starting to learn automation using Selenium and C#, problem is i can navigate to my facebook, google what ever and all works good on firefox. But when using IE browsers it opens the webpage but then throws error 'NoSuchElementException'. I am using same code, one works one does not.
here is IE code
IWebDriver driver = new InternetExplorerDriver(#"C:\folder");
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Hello World");
Here is firefox code
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("Hello World");
This could be timing issue on both browser. You should try using more stable code using WebDriverWait to wait until element is visible before interaction as below :-
IWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.Name("q")));
element.SendKeys("Hello World");

Selenium-WebDriver opened the new Firefox window, but didn’t navigate to URL

My source code is copied from selenium docs site. I didn’t make any change.
http://docs.seleniumhq.org/docs/03_webdriver.jsp#user-input-filling-in-forms
I installed Selenium library via NuGet, including
Selenium Remote Control(RC), Selenium WebDriver Mono, Selenium WebDriver Support Classes, Selenium WebDriver, and Selenium WebDriver-backed Selenium.
When I run this code, a new Firefox window was opened. But the Firefox doesn’t navigate to the URL, it just stuck, nothing was loaded.
I tried the Firefox v27, v29, v30 and v31, none of them worked.
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
// Requires reference to WebDriver.Support.dll
using OpenQA.Selenium.Support.UI;
class GoogleSuggest
{
static void Main(string[] args)
{
// Create a new instance of the Firefox driver.
// Notice that the remainder of the code relies on the interface,
// not the implementation.
// Further note that other drivers (InternetExplorerDriver,
// ChromeDriver, etc.) will require further configuration
// before this example will work. See the wiki pages for the
// individual drivers at http://code.google.com/p/selenium/wiki
// for further information.
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.google.com/");
// Find the text input element by its name
IWebElement query = driver.FindElement(By.Name("q"));
// Enter something to search for
query.SendKeys("Cheese");
// Now submit the form. WebDriver will find the form for us from the element
query.Submit();
// Google's search is rendered dynamically with JavaScript.
// Wait for the page to load, timeout after 10 seconds
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until((d) => { return d.Title.ToLower().StartsWith("cheese"); });
// Should see: "Cheese - Google Search"
System.Console.WriteLine("Page title is: " + driver.Title);
//Close the browser
driver.Quit();
}
}
I have had the same problem. the solution is simply uninstall your current firefox browser and download older version "i tried 2010 version 3.6.10 works great". your code is fine the problem is Mozilla people have decided to not give the right to any third party application to control Firefox.
good luck

selenium doesn't enter the site

I created a console application (with target: .Net Framework 4) and added the next references:
Selenium.WebDriverBackedSelenium.dll
ThoughtWorks.Selenium.Core.dll
WebDriver.dll
WebDriver.Support.dll
static IWebDriver driver = null;
if (driver == null)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
driver = new ChromeDriver(#"C:\selenium\net40", options);
// it opened a new window (about:blank)
}
driver.Navigate().GoToUrl("http://www.facebook.com");
but nothing is happen.
I use: ChromeDriver 26.0.1383.0
and my chrome browser version is: 29.0.1547.62 m
this is the command line:
Started ChromeDriver
port=1866
version=26.0.1383.0
log=C:\Users\salon\Desktop\Application Alon\ConsoleApplication1\ConsoleApplicati
on1\bin\Debug\chromedriver.log
[156:4144:0828/233852:ERROR:platform_thread_win.cc(127)] NOT IMPLEMENTED
[5804:5712:0828/233856:ERROR:textfield.h(173)] NOT IMPLEMENTED
I have windows 7 if it's needed..
any help appreciated!
For the later versions of Chrome (27+), there is a new shiny ChromeDriver:
http://code.google.com/p/chromedriver/downloads/list
Note the section within the summary on the page...
ChromeDriver server for win32 (v2.2.215849.dyu) supports Chrome v27-30
Also, you should remove the Thoughtworks & WebDriverBackedSelenium references, they are not required and you don't seem to be using them.

Categories

Resources