WatiN:尝试在 Google 搜索文本框中键入文本(“WatiN”)时出错

发布于 2024-12-20 06:45:16 字数 889 浏览 1 评论 0原文

我最近刚刚开始研究 WatiN,并遵循 http://www.codeproject 中的示例。 com/KB/aspnet/WatiN.aspx。不幸的是,我遇到了一个问题,它声称名称为“q”的文本字段不存在。

这是我的代码:

    [STAThread]
    static void Main(string[] args)
    {
        IE ie = new IE();
        ie.GoTo("http://www.google.com");
        TextField ietxt = ie.TextField(Find.ByName("q"));
        ietxt.TypeText("WatiN");
        ie.Button(Find.ByValue("Google Search")).Click();

    }

当它到达 ietxt.TypeText("WatiN") 行时,它会抛出错误: “无法在 google.com/ 上找到 INPUT(隐藏)或 INPUT(密码)或 INPUT(文本)或 INPUT(文本区域)或 TEXTAREA 元素标记匹配条件:属性“名称”等于“q”(内部异常:元素不是“ t 在 30 秒内可用。)”

似乎每个人都使用这个示例,并且对他们来说效果很好。我还查看了 google.com 的源代码,并准确地找到了其中指出“q”确实是搜索文本字段的名称的位置。

<input name="q" title="Search" class="gsfi" id="lst-ib" ....>

有谁知道为什么我会收到此错误?

I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx. Unfortunately, I am running into an issue where it is claiming that a text field with the name "q" does not exist.

Here is my code:

    [STAThread]
    static void Main(string[] args)
    {
        IE ie = new IE();
        ie.GoTo("http://www.google.com");
        TextField ietxt = ie.TextField(Find.ByName("q"));
        ietxt.TypeText("WatiN");
        ie.Button(Find.ByValue("Google Search")).Click();

    }

When it gets to the line ietxt.TypeText("WatiN") it throws the error:
"Could not find INPUT (hidden) or INPUT (password) or INPUT (text) or INPUT (textarea) or TEXTAREA element tag matching criteria: Attribute 'name' equals 'q' at google.com/ (inner exception: Element wasn't available within 30 seconds.)"

It seems that everyone uses this example and it works fine for them. Also I went into the source code for google.com and found exactly where it states that "q" is indeed the name of the search text field.

<input name="q" title="Search" class="gsfi" id="lst-ib" ....>

Does anyone have any idea why I could be getting this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木槿暧夏七纪年 2024-12-27 06:45:16

我找到了解决这个问题的方法!通过进一步的测试,我得出的结论是,问题似乎来自于我的机器上 IE 8 的配置方式。我在其他机器上用xp和IE8测试过,一切正常。卸载并重新安装 IE8 已解决该问题。

我仍然不确定我以前的 IE8 版本的配置有何不同,因此如果有人对可能导致此问题的原因有任何想法,我将很高兴听到。

谢谢!

I found a fix for this! From further testing I came to the conclusion that the issue seemed to be coming from how IE 8 was configured on my machine. I tested on other machines with xp and IE8, and everything was working fine. Uninstalling and reinstalling IE8 has cleared up the issue.

I'm still not sure what was configured differently with my past version of IE8, so if anyone has any ideas of what could have caused this I'll be delighted to hear.

Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文