When using the IE driver with IE9, occasionally the Click method will only select a button, it wont do the action of the Click(). Note this only happens occasionally, so i d
I'm experiencing this with 2.0rc2, IE8, Java as well. The problem I have with implementing a solution that can send multiple clicks is that sometimes it does work. In those cases clicking my objects twice does not let the rest of my test move forward. Sending the "Enter" keystroke does not work on our controls either.
There is a similar issue logged for this, but my objects are not necessarily near the "viewpoint". Any more suggestions would be greatly appreciated.
A better way to force the focus on the element is to use Javascript. This works when your elements are tagged with id attribute. If they're not, get the developers to change it.
Find the element using whatever locator/properties you need. Once the element is retrieved, check to see if it contains an ID attribute. If it does, then execute the following code which will force focus to the element:
JavascriptExecutor executor = (JavascriptExecutor) webDriver();
executor.executeScript("document.getElementById('" + element.GetAttribute("id") + "').focus()");
Using this, almost all the issues with missed clicks were resolved when using the InternetExplorerDriver.
I have refactored my solution based on referencing Selenium WebDriver 2.15.0 in my project and using a Selenium WebDriver Server 2.16.0 and I have made the following observations:
FirefoxDriver
RemoteWebDriver
for the DesiredCapabilities.Firefox
RemoteWebDriver
for the DesiredCapabilities.HtmlUnit
and DesiredCapabilities.HtmlUnitWithJavaScript
InternetExplorerDriver
and the RemoteWebDriver
with DesiredCapabilities.InternetExplorer
(really the same thing) are still giving me inconsistent results that I am finding difficult to nail down.My solution to the first three points has been to create my own classes that extend RemoteWebDriver
and RemoteWebElement
so that I can hide my custom behaviour from the test code that continues to reference IRemoteWebDriver
and IWebElement
.
I have below my current "tweaks", but if you go with these custom classes you will be able tweak your driver and web element behaviour to your heart's content without having to change your test code.
public class MyRemoteWebDriver : RemoteWebDriver
{
//Constructors...
protected override RemoteWebElement CreateElement(string elementId)
{
return new MyWebElement(this, elementId);
}
}
public class MyWebElement : RemoteWebElement, IWebElement
{
//Constructor...
void IWebElement.Click()
{
if (Settings.Default.WebDriver.StartsWith("HtmlUnit"))
{
Click();
return;
}
if (TagName == "a")
{
SendKeys("\n");
Thread.Sleep(100);
return;
}
if (TagName == "input")
{
switch (GetAttribute("type"))
{
case "submit":
case "image":
Submit();
return;
case "checkbox":
case "radio":
//Send the 'spacebar' keystroke
SendKeys(" ");
return;
}
}
//If no special conditions are detected, just run the normal click
Click();
}
}
I am using IE version: 9 Was facing the same issue. The following worked in my case
element.sendKeys(Keys.ENTER);
element.click();
After a bit more searching i found two things that seem to have helped in repeatable tests:
First i added an ImplicitlyWait of 5 seconds. Not sure if this is applied to all FindElement functions, but I have stopped getting most of the NoSuchElementException i was getting.
OpenQA.Selenium.IE.InternetExplorerDriver driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 5, 0));
//driver.Manage().Speed = Speed.Medium;
Second i was having trouble with a Logout function and changed the code to:
public LoginPageObject Logout() {
Driver.FindElement(By.LinkText("Logout")).Click();
OpenQA.Selenium.Support.UI.IWait<IWebDriver> wait = new OpenQA.Selenium.Support.UI.WebDriverWait(Driver, TimeSpan.FromSeconds(5));
IWebElement element = wait.Until(driver => driver.FindElement(By.Name("username")));
LoginPageObject lpage = new LoginPageObject(Driver);
return lpage;
}
The explicit wait seems to handle what the ImplicitlyWait doesn't catch (i think because of redirects).
http://code.google.com/p/selenium/source/browse/trunk/support/src/csharp/webdriver-support/UI/WebDriverWait.cs?r=10855
My solution was:
Selenium WebDriver 2.29.0 (JAVA), TESTED with FF16 and IE9
Before to make a findElement, I did a maxime browser screen. It works fine.
public void maximeBrowser() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenResolution = new Dimension((int)toolkit.getScreenSize().getWidth(), (int)toolkit.getScreenSize().getHeight());
//Maximize the browser
logger.info("Maximizing the browser : getWidth ["+screenResolution.getWidth()+"] - getHeight ["+screenResolution.getHeight()+"]");
getDriver().manage().window().maximize();
}