Selenium 2.0b3 IE WebDriver, Click not firing

后端 未结 18 1923
我寻月下人不归
我寻月下人不归 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 03:05

    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:

    • The click event does fire correctly when using the FirefoxDriver
    • The click event does not fire correctly for certain controls when using the RemoteWebDriver for the DesiredCapabilities.Firefox
    • The click event does fire correctly when using the RemoteWebDriver for the DesiredCapabilities.HtmlUnit and DesiredCapabilities.HtmlUnitWithJavaScript
    • The 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();
        }
    }
    

提交回复
热议问题