从任何浏览器(IE,Chrome,FireFox等)获取文本

编程入门 行业动态 更新时间:2024-10-25 12:22:14
本文介绍了从任何浏览器(IE,Chrome,FireFox等)获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的朋友, 我有以下代码:

Dear Friends, I have the following code:

private void button1_Click(object sender, EventArgs e) { Process[] plist = Process.GetProcesses(); foreach (Process p in plist) { if (p.ProcessName == "notepad") { AutomationElement ae = AutomationElement.FromHandle(p.MainWindowHandle); AutomationElement npEdit = ae.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "Edit")); TextPattern tp = npEdit.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] trs; if (tp.SupportedTextSelection == SupportedTextSelection.None) { return; } else { trs = tp.GetSelection(); label1.Text = trs[0].GetText(-1); } } } }

上面的代码用于从任何窗口获取选定的文本",但在某些浏览器(IE,Chrome,Firefox)中不起作用,这行的主要问题

The above code is used to get Selected Text form any window but it is not working in some browsers (IE, Chrome, Firefox), The main problem in this line

AutomationElement ae = AutomationElement.FromHandle(p.MainWindowHandle);

在浏览器中,P.MainWindowHandle始终为return 0.请帮忙. 谢谢.

The P.MainWindowHandle always return 0 in the case of browser. Please help. Thanks.

推荐答案

当我替换p.ProcessName =="iexplore"时,我得到的p.MainWindowHandle的值不同于0 然后我得到的问题是,它找不到名称为Edit的ClassNameProperty. When I replace p.ProcessName == "iexplore" I do get a p.MainWindowHandle different of 0 Then the problem I get is that it does not find a ClassNameProperty with name Edit.

更多推荐

从任何浏览器(IE,Chrome,FireFox等)获取文本

本文发布于:2023-11-24 18:46:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   浏览器   Chrome   FireFox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!