我正在尝试使用Selenium。这是我的简单代码。打开StackOverflow并在搜索框中输入sdf。 IE出现并导航到正确的页面。事情就发生了。看一下输出。这是一个控制台应用程序。
更新:我查看了驱动程序中的HTML ...它正在查看Selenium的起始页。
CODE:
IWebDriver _driver;
_driver = new InternetExplorerDriver();
_driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
_driver.Navigate().GoToUrl("http://www.stackoverflow.com/");
Console.WriteLine(_driver.PageSource);
_driver.FindElement(By.Name("q")).Clear();
_driver.FindElement(By.Name("q")).SendKeys("sdf");
输出:
Started InternetExplorerDriver server (64-bit)
2.28.0.0
Listening on port 60181
<HTML><HEAD><TITLE>WebDriver</TITLE></HEAD>
<BODY>
<P id=main>This is the initial start page for the WebDriver server.</P></BODY></HTML>
Unable to find element with name == q
DONE
答案 0 :(得分:0)
尝试使用其他定位器
By.cssSelector()
By.id()
By.xpath()
答案 1 :(得分:0)
这个CSS应该有用。
表单#search div输入
答案 2 :(得分:0)
尝试使用//input[@name='q' and @placeholder='search']