本文介绍了从任何浏览器(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等)获取文本
发布评论