Selenium webdriver: IE 11.Click () element not working

I tried to find any solution but nothing worked for me.

I have this item

<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\']"));

      

This is not a problem with this part. But if you try to click on this element in IE11, it won't work

find.Click()

      

I tried some solution like:

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

      

But nothing happened. In Chrome and Firefox normal click on an element. If I click on other elements, for example the button works on IE 11. But I need to click on this element.

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

+3


source to share


2 answers


In IE, you always have to do something extra. Try this "special" trick:



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

      

+2


source


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

Also, it is good practice to remember to always scroll the element in view, an example of a wrapper function:



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 example of what's in between, I can help further. Good luck!

0


source







All Articles