C# 中的 SendKeys 类
我有一个 c# 程序,它使用 Process 类来启动 Internet Explorer 并转到某个 url。
然后,它将特定字符串发送到该页面的搜索框,复制返回结果的整个屏幕,并对其进行处理。
我遇到的问题是这样的:
我使用 SendKeys.SendWait("abc") 将字符串发送到 Internet Explorer 中的页面(活动窗口)。 当程序运行时,我看到页面上填充的内容有时是“bc”,有时是“abbc”,有时是“abcc”,有时是正确的“abc”。 每次跑步看起来都完全不同。 我测试的多台机器上都出现了这个问题。 但在我自己的机器上,也就是我最初开发这个的地方,我从未见过它发生——只有当我在其他机器上测试它时(所有机器都运行 XP)。
我在 SendWait 语句之间添加了延迟,以解决随机计时问题,但我是否相信即使在相同的 SendWait 语句中也存在问题?
需要帮助。 谢谢。
I have a c# program that uses the Process class to launch Internet Explorer and goes to a url.
It then sends in specific strings to the search box of that page, copies the whole screen of the returned results, and processes it.
The problem I encountered is this:
I use SendKeys.SendWait("abc") to send the string to the page in Internet Explorer (the active window). As the program is running, I see that what is being populated on the page is sometimes "bc", sometimes "abbc", sometimes "abcc", and sometimes correctly "abc". Each run looks totally different. This problem happened on multiple machines I tested. But on my own machine, where I originally developed this, I've never seen it happen - only when I test it on other machines (all running XP).
I put in delays in between SendWait statements to take care of random timing issues, but am I to believe that even within the same SendWait statements there are issues?
Help needed. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试获取网页的源代码,那么我建议您使用类似的内容
如果您尝试获取页面上呈现的文本,那么我建议您查看 HtmlAgilityPack,它应该可以帮助您更轻松地获取页面内容并使其更加具体。
或者,您可以使用正则表达式来选择 div 标签之间的文本:
警告,该代码是我凭空想象出来的,未经测试,并且可能会导致一些带有嵌套标签的相当随机的结果:)
If you are attempting to grab source of a web page, then I'd suggest using something like
If you are attempting to grab the text that gets rendered on the page, then I'd recommend looking at the HtmlAgilityPack which should allow you to much more easily grab the content of the page as well as making it more specific.
Alternatively, you could make use of a RegEx to select the text between, say, div tags:
Warning, that code was written off the top of my head, untested, and will probably result in some pretty random results with nested tags :)