Tomáš Kukučka
Tomáš Kukučka

Reputation: 68

Selenium webdriver: IE 11 element.Click() doesnt work

I tried to find any solution but nothing is not helped me.

I have this element

<span data-lkd="GUI-411396" data-lkta="tc" data-lkda="title" class="panelbar_item" title="Hledat">Form</span>

In Selenium I find it with

IWebElement form = GetElementAndWaitForEnabled(By.CssSelector("span[data-lkd=\'GUI-411396\']"));

It's not problem to this part. But if try click on this element in IE11 nothing happend

find.Click()

I tried some solution like:

driver.SwitchTo().Window(driver.CurrentWindowHandle);
find.SendKeys(Keys.Enter);
find.Click();

But nothing happend. In Chrome and Firefox is normaly click on element. If I clik in other elements for example button it works on IE 11. But I need click on this element.

I'm using Selenium v2.46.0, IE 11 (x86, x64).

Upvotes: 3

Views: 3648

Answers (2)

TOlson05
TOlson05

Reputation: 41

It looks like you are trying to click on a span element. Instead of using a work around to click on the span element and trying to get the desired effect, try checking to see if it is wrapped in an anchor element or input / button element.

As an aside a good practice is to remember to always scroll the element into view, an example wrapper function would be:

public static void clickElementAsUser(WebDriver driver, By by)
{
    WebElement element;

    try
    {
        element = driver.findElement(by);
        scrollElementIntoView(driver, element);
        Thread.sleep(100); //Wait a moment for the element to be scrolled into view
        element.click();
    }
    catch(Exception e) //Could be broken into multicatch
    { 
        //Do Something
    }
}

public static void scrollElementIntoView(WebDriver driver, WebElement element)
{
    try
    {
        ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
    }
    catch(Exception e)
    {
        //Do Something
    }
}

If you post a small code sample of what is aroudn the span I may be able to help further. Goodluck!

Upvotes: 0

alecxe
alecxe

Reputation: 473763

With IE, it's always something extra you should do. Try this "special" trick:

IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", find)

Upvotes: 2

Related Questions