我只是下载并构建了WatiN,并在他们的站点上运行了示例(没有几行代码):
using (var browser = new IE("http://www.google.com"))
{
browser.TextField(Find.ByName("q")).TypeText("WatiN");
}但在运行时,Google不会显示即时结果,因此似乎某些事件没有被正确触发,无法真正模拟用户输入。知道WatiN (或上面的代码)缺失了什么吗?如何修复?
发布于 2013-08-22 16:39:18
如果我测试您的代码,它将执行您编写的代码。
打开浏览器,在"q“textfield
即时结果有效,打字有效。到底是什么对你不起作用?
我建议不要使用using,我知道这听起来很疯狂,但是浏览器在被释放时会关闭,你也可以自己关闭它。
发布于 2013-08-22 16:57:04
使用以下方法
var url = "http://www.google.co.in/?gws_rd=cr";
//Create an IE browser instance
var browser = new IE();
browser.GoTo(url);
// Wait for the browser to load properly.
browser.WaitForComplete();
//Find the Search textbox
var txtSearch = browser.TextField(Find.ByName("q"));
if (!txtSearch.Exists)
{
//log error here as the elemnt with property specified is not found
}
// Assign the value (what you want to search)
txtSearch.Value = "WATIN";
// Find the search button
var btnSearch = browser.Button(Find.ByName("btnG"));
if (!btnSearch.Exists)
{
//log error here as the elemnt with property specified is not found
}
//Click the search button
btnSearch.Click();
// Now you have search results so you can do whatever operations you want to perform
//When done, close the browser.
browser.Close();https://stackoverflow.com/questions/18308401
复制相似问题