Selenium 2.0b3 IE WebDriver, Click not firing

后端 未结 18 1914
我寻月下人不归
我寻月下人不归 2020-11-29 02:33

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

18条回答
  •  既然无缘
    2020-11-29 02:41

    None of the above solutions worked for me. This did the trick tho:

    Java

    element.sendKeys(org.openqa.selenium.Keys.CONTROL);
    element.click();
    

    Groovy

    element << org.openqa.selenium.Keys.CONTROL
    element.click()
    

    Geb

    Or, if you're using Geb, there's an even better solution that's completely unobtrusive:

    (tested with IE7 and Geb 0.7.0)

    abstract class BaseSpec extends geb.spock.GebSpec
    {
        static
        {
            def oldClick = geb.navigator.NonEmptyNavigator.metaClass.getMetaMethod("click")
            def metaclass = new geb.navigator.AttributeAccessingMetaClass(new ExpandoMetaClass(geb.navigator.NonEmptyNavigator))
    
            // Wrap the original click method
            metaclass.click = {->
                delegate << org.openqa.selenium.Keys.CONTROL
                oldClick.invoke(delegate)
            }
    
            metaclass.initialize()
    
            geb.navigator.NonEmptyNavigator.metaClass = metaclass
        }
    }
    
    class ClickSpec extends BaseSpec
    {
        def "verify click"()
        {
            given:
            to HomePage
    
            expect:
            waitFor { at HomePage }
    
            when:
            dialog.dismiss()
            // Call the wrapped .click() method normally
            $('#someLink').click()
    
            then:
            waitFor { at SomePage }
        }
    }
    
    class HomePage extends geb.Page
    {
        static url = "index.html"
        static at = { title == "Home - Example.com" }
        static content = {
            dialog { module DialogModule }
        }
    }
    
    class SomePage extends geb.Page { ... }
    class DialogModule extends geb.Module { def dismiss() { ... } }
    

    In my case, clicking in IE7 appeared to fail whenever it was preceded by the closing of an animated modal overlay (we're using jQuery Tools Overlay Modal Dialog). The Geb method above solved this problem.

提交回复
热议问题