Some elements take too long to be identified when

2019-07-23 03:28发布

问题:

Let's say I have an automated test case that launches Google.com and searches for a string.

  • Launch google.com
  • Search "Malaysian Airline"

I have all the necessary properties for search field identified so that playback can find this very easy and run through it. But, when I run the test, it takes up to 10-14 seconds only to find the search field in Google.com and then searching in it.

My Code is

BrowserWindow browser = BrowserWindow.Launch("www.google.com");
            UITestControl UISearch = new UITestControl(browser);
            UISearch.TechnologyName = "Web";
            UISearch.SearchProperties.Add("ControlType", "Edit");
            UISearch.SearchProperties.Add("Id", "lst-ib");
            Mouse.Click(UISearch);
            Keyboard.SendKeys(UISearch, "Malaysian Airline");

You guys could also try it out. There are next to nothing else on Google.com still it takes too long to find the element where I have already given possible and the only unique Id.

回答1:

Using Selenium on firefox it's 10 seconds where \n pressed enter and avoiding the cost of hovering and clicking on the element.

[TestClass]
public class UnitTest1
{
    FirefoxDriver firefox;

    // This is the test to be carried out.
    [TestMethod]
    public void TestMethod1()
    {
        firefox = new FirefoxDriver();
        firefox.Navigate().GoToUrl("http://www.google.com/");
        IWebElement element = firefox.FindElement(By.Id("lst-ib"));
        element.SendKeys("Google\n");
    }

    // This closes the driver down after the test has finished.
    [TestCleanup]
    public void TearDown()
    {
        firefox.Quit();
    }
}