3

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).

1

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

Comments

0

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!

2 Comments

Instead of waiting for waiting for 100ms, Thread.sleep(100), it is a better practice to wait for an element to be visible, just my own personal preference. :-)
Very true, sleeping could result in over waiting or under waiting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.