Selenium 中抓取dropdown

 个人站点地址:nowherewoman.com

Problem: Below is the html for dropdown 




And list
 

Solution 1:

 refer to Selenium IDE :
BrowserSeleniumHelper.ClickElementByCssSelector("#SettingTabStrip-2 span.t-input");
BrowserSeleniumHelper.ClickElementByXpath("//div[8]/div/ul/li[2]");
 
Solution 2: 
BrowserSeleniumHelper.InputElementByXpath("//div[@id='SettingTabStrip-2']/div[@class='horizontalLine']/ul/li/div/div/span", "China Kids & Teens");
 
      this solution can't capture the value change event
 
Solution 3: 
BrowserSeleniumHelper.ClickElementByCssSelector("#SettingTabStrip-2 span.t-input"); BrowserSeleniumHelper.SendArrowDownByCssSelector("#SettingTabStrip-2 span.t-input"); BrowserSeleniumHelper.SendEnterByCssSelector("#SettingTabStrip-2 span.t-input");
 
 
Event Reference
     public static void ClickElementByCssSelector(string spanTInput)
        {
            Driver.FindElement(By.CssSelector(spanTInput)).Click();
        }
 
public static void SendArrowDownByCssSelector(string css)
        {
            Driver.FindElement(By.CssSelector(css)).SendKeys(Keys.ArrowDown);
        }
 
public static void SendEnterByCssSelector(string css)
        {
            Driver.FindElement(By.CssSelector(css)).SendKeys(Keys.Enter);
        }
原文地址:https://www.cnblogs.com/NowhereWoman/p/3656626.html