我使用 WatiN 在我的网站上自动提交表单。我遇到的问题是我找不到任何关于如何在提交后搜索页面并验证字符串是否存在的文档。我需要它在结果页面中查找一个字符串,如果它存在,则继续在列表中插入下一个变量,如果它不存在,我需要它来记录插入的字符串导致文本不显示,最好在文本文件中。到目前为止,这是我的代码。
browser.GoTo("https://site.com");
// locate the form by name and fill it
browser.TextField(Find.ByName("form")).TypeText("example");
// click the submit button
browser.Button(Find.ByName("submit")).Click();
不幸的是,这就是我所得到的。感谢帮助,我只需要被推向正确的方向。
最佳答案
使用 browser.ContainsText("text to find")
验证字符串是否存在。
string[] textToAddList = File.ReadAllLines(@"C:\Users\Syd\Desktop\list.txt");
browser.GoTo("https://site.com");
foreach (string textToAdd in textToAddList)
{
browser.TextField(Find.ByName("form")).TypeText(textToAdd);
browser.Button(Find.ByName("submit")).Click();
browser.WaitUntilComplete();
if (!browser.ContainsText("text to find"))
{
//Log here
break;
}
}
关于c# - 自动提交表单后搜索浏览器内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10628509/