Selenium 实现联想下拉框

直接在文本框输入字符,并不能实现联想下拉框,

第一种方式:强制执行js

            driver.FindElement(By.Id("top_search_input")).SendKeys("a");
            var js_displayTheMenuBlock = string.Format("document.querySelector('#userSearchBox').style.display= 'block'");//找到js改变属性
            ((IJavaScriptExecutor)driver).ExecuteScript(js_displayTheMenuBlock);//强制执行js

 第二种方式:根据网页设计原理,可以使用输入字符然后 加 “空格”来实现

            driver.FindElement(By.Id("top_search_input")).SendKeys("a");
            driver.FindElement(By.Id("top_search_input")).SendKeys("");//""表示空格

第三种方式:可以输入字符 加“点击”来实现

            driver.FindElement(By.Id("top_search_input")).SendKeys("a");
            driver.FindElement(By.Id("top_search_input")).Click();
原文地址:https://www.cnblogs.com/cloud-test/p/3469515.html