C# 跳转一些文本字段,如搜索框
我只是使用 watin 来填充一些文本字段,但是有时它会写在错误的文本字段中,因为文本字段名称不清楚这是我的代码
IE browser = new IE(site);
browser.TextField(Find.By("type","text")).TypeTextQuickly(username.ToString());
browser.TextField(Find.By("type", //"password")).TypeTextQuickly(pass.ToString());
browser.Button(Find.By("type", "submit")).Click();
I'm just using watin to fill some textfields but sometimes it writes in the wrong textfield because the textfields name is not clear here's my code
IE browser = new IE(site);
browser.TextField(Find.By("type","text")).TypeTextQuickly(username.ToString());
browser.TextField(Find.By("type", //"password")).TypeTextQuickly(pass.ToString());
browser.Button(Find.By("type", "submit")).Click();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑您的输入元素的 HTML 代码和设置 ID。然后使用Find.ById
Edit your HTML code and setup ID´s for your input elements. Then use Find.ById
一种选择可能是首先查看是否存在可以找到的外部元素(例如
Div
),然后从该元素而不是从浏览器变量获取文本字段。例如,它可能看起来像这样:One option could be to see if there is an outer element (such as a
Div
) you can find first, and afterwards get the text fields from that element instead of from the browser variable. That could for instance look like this:我不清楚你对 WatiN 和测试的了解,所以我将从乞讨开始。首先,您需要进入要测试的网页并(在 IE 中)转到“工具”->“开发者工具。单击菜单中的白色箭头,然后继续单击您要使用的框。执行此操作后,开发人员工具将为您提供文本框的代码,包括您可以在代码中引用它的多种方式。例如,使用 IE 中的开发工具,我可以像这样自动登录到我的 gmail:
有很多 Find.By 命令,因此您没有理由无法访问您想要的任何文本字段。您只需要 html 并具体说明要写入哪一个。我希望这有帮助:)
I am unclear as to your knowledge of WatiN and testing so I will start from the begginging. First you need to go on the webpage you want to test and (in IE) go to tools -> Developer tools. Click the white arrow in the menu then proceed to click the box you wish to utilize. Once you do this the developer tools will give you the code for the textbox including many ways you can reference it in your code. For example, using dev tools in IE I can automate logging into my gmail like this:
There are many Find.By commands so there is no reason you can't acess ANY textfield you wish. You just need the html and to be specific to which one you want to write into. I hope this helps :)