简体   繁体   中英

How to click on the first index in search drop down using selenium C#

        IWebDriver driver = new ChromeDriver();
        driver.Navigate().GoToUrl("http://www.yahoo.com");
        driver.Manage().Window.Maximize();
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
        driver.Manage().Window.Maximize();
        driver.FindElement(By.XPath("//*[@id='uh-search-box']")).SendKeys("selenium");
        Thread.Sleep(5000);
        IList<IWebElement> list = driver.FindElements(By.XPath("//*[starts-with(@id,'yui_3_18_0_6_1472')]"));

         for (int i=0; i<list.Count; i++)
        {
            IWebElement element = list[1];
            element.Click();
        }

}

Need to click on the first index (first suggested result in search field) the code above does not work please help http://screencast.com/t/gbWTiXzuDmC

尝试使用这样的xPath //*[@role='option']并在WebElements列表中获得第一项

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM