Is there a way to copy highlighted text?
This is in a browser. A solution for just IE (Com Interface?) would do just fine. However i am looking for a general solution.
1. Click find.
2. Enter a string (mine is quite unique so if found it finds only one case)
3: Send and the found string is highlighted.
3. Copy the highlighted text.
Plan B if highlighted text cannot be copied: If "find" function finds the word, is there a return value that can be read? (Much like Errorlevel?)
Thanks
PS: I thought highlighted text as a result of a"Find" search was the same as highlighted text marked by hand with the mouse. Apparently not.
Copy highlighted text
- Sir Teddy the First
- Posts: 94
- Joined: 05 Aug 2019, 12:31
- Contact:
Re: Copy highlighted text
Hi,
just a question: Why do you want to copy the text that got highlighted as a result of a search for text that you entered?
Wouldn't that just be the same text?
just a question: Why do you want to copy the text that got highlighted as a result of a search for text that you entered?
Wouldn't that just be the same text?
Re: Copy highlighted text
NO. If the search is case-insensitive the returned text could be with a different case than the searched text.Sir Teddy the First wrote: ↑16 Aug 2019, 15:42Hi,
just a question: Why do you want to copy the text that got highlighted as a result of a search for text that you entered?
Wouldn't that just be the same text?
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
- Sir Teddy the First
- Posts: 94
- Joined: 05 Aug 2019, 12:31
- Contact:
Re: Copy highlighted text
So, couldn't you just check in the Source-Code of the webpage if the text with your preferred case is present?
I'm sorry if I'm asking dumb questions, I just try to understand your problem
I'm sorry if I'm asking dumb questions, I just try to understand your problem
Re: Copy highlighted text
Do the following (just an example):
1. open IE
2. navigate to https://www.roboform.com/filling-test-all-fields
3. press Ctrl+f
4. type 'Middle initial'
The text is highlighted in the page. I want to copy that text. Preferably with Ctrl+c but it doesn't work.
Neither the mouse arrow or the marker are at the text.
1. open IE
2. navigate to https://www.roboform.com/filling-test-all-fields
3. press Ctrl+f
4. type 'Middle initial'
The text is highlighted in the page. I want to copy that text. Preferably with Ctrl+c but it doesn't work.
Neither the mouse arrow or the marker are at the text.
- Sir Teddy the First
- Posts: 94
- Joined: 05 Aug 2019, 12:31
- Contact:
Re: Copy highlighted text
So,
I now understand what you want to do, but I don't understand why?
would do the same thing. And you have to know what text you want to search for, why don't you just capitalize that?
I now understand what you want to do, but I don't understand why?
Code: Select all
StringUpper, OutputVar, InputVar , T
Re: Copy highlighted text
Good point. I was unclear.Sir Teddy the First wrote: ↑16 Aug 2019, 15:42Hi,
just a question: Why do you want to copy the text that got highlighted as a result of a search for text that you entered?
Wouldn't that just be the same text?
I search for a text that may or may not be in the page. If it worked to copy with Ctrl+c (which it does not) then an empty Clipboard would indicate that the string wasn't found.
Re: Copy highlighted text
Actually it doesn't matter that is is lower or upper case. I just want to check if the text exists in the page or not.Sir Teddy the First wrote: ↑17 Aug 2019, 02:42So,
I now understand what you want to do, but I don't understand why?
would do the same thing. And you have to know what text you want to search for, why don't you just capitalize that?Code: Select all
StringUpper, OutputVar, InputVar , T
If you repeat by hand the process i described above the string will be highlighted. Do Ctrl+c by hand and paste in Notepad. The string has not been copied.
- Sir Teddy the First
- Posts: 94
- Joined: 05 Aug 2019, 12:31
- Contact:
Re: Copy highlighted text
Hi,
just another suggestion, if you don't want to do it that way, we're going your way.
I just checked that, if you operate via COM, every name of those fields is contained in the HTML-class named "rfcontent clearfix".
So if you read this class into a variable, you can always check with "InStr" (even with case-sensitive search turned on) if it is present.
If we're talking not only about this page, but in gerneral, you would just have to get the source code via "Ctrl+U" and search that.
Is that an option?
just another suggestion, if you don't want to do it that way, we're going your way.
I just checked that, if you operate via COM, every name of those fields is contained in the HTML-class named "rfcontent clearfix".
So if you read this class into a variable, you can always check with "InStr" (even with case-sensitive search turned on) if it is present.
If we're talking not only about this page, but in gerneral, you would just have to get the source code via "Ctrl+U" and search that.
Is that an option?
Re: Copy highlighted text
Thanks. It is a good alternative option.Sir Teddy the First wrote: ↑17 Aug 2019, 02:48Hi,
just another suggestion, if you don't want to do it that way, we're going your way.
I just checked that, if you operate via COM, every name of those fields is contained in the HTML-class named "rfcontent clearfix".
So if you read this class into a variable, you can always check with "InStr" (even with case-sensitive search turned on) if it is present.
If we're talking not only about this page, but in gerneral, you would just have to get the source code via "Ctrl+U" and search that.
Is that an option?
I had solved it temporarily with WinGetText storing the returned value in a variable and searching in it.
Still I would like to have the easiest solution which is to copy with Ctrl+c the highlighted text. The string I am searching for is so specific that I know if it exists, it will be found only once.
Funny enough after Ctrl+u I do a Ctrl+f in the new page with the search string which is highlighted and as in the first case it CAN NOT be copied with Ctrl+c
Last edited by aircooled on 17 Aug 2019, 03:08, edited 2 times in total.
Re: Copy highlighted text
Correct. And the case -upper or lower- is totally irrelevant in my scenario. I just need to check whether the string exists or not.Odlanir wrote: ↑17 Aug 2019, 01:19NO. If the search is case-insensitive the returned text could be with a different case than the searched text.Sir Teddy the First wrote: ↑16 Aug 2019, 15:42Hi,
just a question: Why do you want to copy the text that got highlighted as a result of a search for text that you entered?
Wouldn't that just be the same text?
Last edited by aircooled on 17 Aug 2019, 03:07, edited 1 time in total.
Re: Copy highlighted text
As an alternative plan:
If Ctrl+f finds a string. Is there any returned system value (like Errorlevel?) that indicates FOUND or NOT FOUND? That would be good enough for me.
If Ctrl+f finds a string. Is there any returned system value (like Errorlevel?) that indicates FOUND or NOT FOUND? That would be good enough for me.
- Sir Teddy the First
- Posts: 94
- Joined: 05 Aug 2019, 12:31
- Contact:
Re: Copy highlighted text
Hi,
I just tested something:
If you use your method and search for the text and it is highlighted and you are sure that it appears only once, what I did was the following:
I searched for it via Ctrl+F (it got highlighted), I pressed "Next" (or Shorcut "Enter") which did not really do anything because it appears only once, but afterwards I was able to copy it with Ctrl+C, sometimes I had to press that twice, but that is something that AHK can do as well, i.e. "if the Clipboard is still empty -> Copy again" or something like that.
But it actually worked the way you wanted it to.
I just tested something:
If you use your method and search for the text and it is highlighted and you are sure that it appears only once, what I did was the following:
I searched for it via Ctrl+F (it got highlighted), I pressed "Next" (or Shorcut "Enter") which did not really do anything because it appears only once, but afterwards I was able to copy it with Ctrl+C, sometimes I had to press that twice, but that is something that AHK can do as well, i.e. "if the Clipboard is still empty -> Copy again" or something like that.
But it actually worked the way you wanted it to.
Re: Copy highlighted text
Brilliant! It did the job and brought tears to my eyes...Sir Teddy the First wrote: ↑17 Aug 2019, 03:26Hi,
I just tested something:
If you use your method and search for the text and it is highlighted and you are sure that it appears only once, what I did was the following:
I searched for it via Ctrl+F (it got highlighted), I pressed "Next" (or Shorcut "Enter") which did not really do anything because it appears only once, but afterwards I was able to copy it with Ctrl+C, sometimes I had to press that twice, but that is something that AHK can do as well, i.e. "if the Clipboard is still empty -> Copy again" or something like that.
But it actually worked the way you wanted it to.
And allows me to implement the simplest solution that's always the best.
Thank you!
-
- Posts: 4344
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Copy highlighted text
@aircooled, also you could find, select and copy some text in IE by this way:
Code: Select all
url := "https://www.roboform.com/filling-test-all-fields"
text := "middle initial"
if !wb := GetIePagePwbByUrl(url) {
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate(url)
while (wb.Busy || wb.ReadyState != 4)
Sleep 10
}
if !SelectTextInIE(wb, text)
MsgBox, Text not found
else
Clipboard := GetSelected(wb)
SelectTextInIE(wb, text) {
rng := wb.document.body.createTextRange()
if !rng.findText(text)
Return
rng.select()
Return true
}
GetSelected(wb) {
static IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"
, VT_DISPATCH := 9, F_OWNVALUE := 1
pWin := ComObjQuery(wb, IID_IHTMLWindow2, IID_IHTMLWindow2)
window := ComObject(VT_DISPATCH, pWin, F_OWNVALUE)
res := window.eval("window.getSelection().toString()")
ObjRelease(pWin)
Return res
}
GetIePagePwbByUrl(url) {
for window in ComObjCreate("Shell.Application").Windows
if InStr(window.FullName, "iexplore.exe") && RegExMatch(url . "/", "i)^\Q" . window.LocationURL . "\E/*$")
Return window
}
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 240 guests