KnowBrainer Speech Recognition
Decrease font size
Increase font size
Topic Title: How Do I Access an EXISTING Internet Explorer Window
Topic Summary:
Created On: 05/21/2018 10:46 PM
Status: Post and Reply
Linear : Threading : Single : Branch
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/21/2018 10:46 PM  
 How Do I Access an EXISTING Internet Explorer Window   - PG LTU - 05/22/2018 10:51 AM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/22/2018 03:23 PM  
 How Do I Access an EXISTING Internet Explorer Window   - PG LTU - 05/22/2018 06:14 PM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/22/2018 10:23 PM  
 How Do I Access an EXISTING Internet Explorer Window   - PG LTU - 05/23/2018 10:49 AM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/23/2018 11:55 AM  
 How Do I Access an EXISTING Internet Explorer Window   - PG LTU - 05/23/2018 04:07 PM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/24/2018 05:38 PM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/24/2018 07:15 PM  
 How Do I Access an EXISTING Internet Explorer Window   - Lunis Orcutt - 05/24/2018 07:46 PM  
 How Do I Access an EXISTING Internet Explorer Window   - AlexF - 05/24/2018 07:57 PM  
 How Do I Access an EXISTING Internet Explorer Window   - PG LTU - 05/25/2018 09:42 AM  
Keyword
 05/21/2018 10:46 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

I need to manipulate an IE window once it is already open, not launch a new IE window.

 

Specifically, I spend a lot of time doing research in a special database (Westlaw), and - when I find a case which is helpful - I will run a vba command which saves the webpage to my computer, using vba to click various buttons, etc.

 

It wouldn't be useful to create a new IE window, by using the normal Set IE = New InternetExplorer command, because then I'd lose the case, and have to log in to the database all over again.   I need to start with the webpage I'm on, and then manipulate the open webpage.

 

I've tried things like substituting Set IE = GetObject(, "InternetExplorer.Application")

instead of

Set IE = New InternetExplorer

 

But nothing's working.  Any tips?



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.

 05/22/2018 10:51 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Here's a tip:  Open the shell object, iterate through all open windows (you will get both Explorer and IE windows and tabs) looking for a title or text, and when you find it, save that one to your IE object.  Simple, I've explained it all before:

 

http://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=23806

 

Also, if it's the active IE window you are in, then it is even easier.  Here is an older example (it's a ways down near the bottom of the thread):

 

http://www.knowbrainer.com/forums/forum/messageview.cfm?catid=12&threadid=21027

 

Let us know how you make out . . .



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 05/22/2018 03:23 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

PG,

 

When I try to use the second technique, I get the following error:

 

(10091) ActiveX Automation: no such property or method.  - WSAStartup cannot function at this time because the underlying system it uses to provide network services is currently unavailable.

 

Am I not using the right reference libraries? Or is this a problem with my computer (e.g. dll files)?  I'm going crazy trying to figure this out.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.

 05/22/2018 06:14 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Still works for me.  No external references needed. Make Google the active IE page and the active window, but make sure you click outside the google search box so the cursor is not blinking in it. Then issue this command and watch as 5 seconds later the cursor shows up there ready for you to dictate your query:

Sub Main
    Dim wb As Object ' prepare a web browser object
    Wait 5 ' use this time to activate the google page and click outside the search box if needed (e.g., in debug mode)
    Set wb = CreateObject("Shell.Application").Windows.Item(0) ' set the wb object to the active window, namely Item(0)
    wb.Visible = True ' wb must be visible to the code for it to act
    wb.Document.getElementByID("lst-ib").focus() ' "lst-ib" is the search box element ID on the google page
    Set wb = Nothing
End Sub


Hth,



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 05/22/2018 10:23 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

Your script worked perfectly. However, when I change   

 

wb.Document.getElementByID("lst-ib").focus()

 

to either

 

wb.Document.getElementsByClassName("btnK").click()

 

or

 

wb.Document.getElementsByName("btnK").click()

 

I get the same error message. So I must be doing something wrong in how I write the click command.

 

By the way, when I instead use

 

wb.Document.getElementsByName("btnK").Item(0).click()

 

Then I get the following error:

 

(10094) ActiveX Automation: Object var is ‘Nothing”.

 

I can't figure out what I'm doing wrong ... I can't even click the Google search button.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.

 05/23/2018 10:49 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Oh so close. Did you search for the vba syntax? Here it is:

wb.Document.getElementsByName("q")(0).focus() ' focus on search input box by element name
wb.Document.getElementsByName("btnK")(0).click() ' click the search button by element name


Now you should have some fun . . .

-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.

 05/23/2018 11:55 AM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

PG,

 

If I leave in both of these lines:

 

wb.Document.getElementByID("lst-ib").focus() 
wb.Document.getElementsByName("btnK")(0).click()

 

I get the error

 

(10510) Not an object reference.

 

If I delete the focus line and only include wb.Document.getElementsByName("btnK")(0).click()

 

I get the error

 

(10094) ActiveX Automation: Object var is ‘Nothing’.

 

I'm using a brand new HP Pavillion laptop, so there's no way my .dll files are corrupted.

 

By the way, I don't know a good source for searching VBA syntax.  I read Larry Allen's book, and find examples on Know Brainer, Stack Exchange, etc.  I find actual Microsoft discussions hard to read.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.



 05/23/2018 04:07 PM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Sure, I get it - it can seem intractable. I had to click a few links before getting enough info to trial and error it. I searched "vba getelements by name" to get a collection of links. Anyway, we'll get you going. Pls provide your whole script. Here's mine:

Sub Main
    Dim wb As Object ' prepare an object
    Wait 5 ' use this time to activate the IE google page but click outside the search box
    Set wb = CreateObject("Shell.Application").Windows.Item(0) ' set the wb object to the active window
    wb.Visible = True ' wb must be visible to the code for it to act
    wb.Document.getElementByID("lst-ib").focus() ' go to search box by ID
    Wait 2
    SendKeys "star +{tab}" ' shift tab leaves the box
    Wait 2
    wb.Document.getElementsByName("q")(0).focus() ' a different way to go to search box 
    Wait 2
    SendKeys "trek+{tab}"
    Wait 2
    wb.Document.getElementsByName("btnK")(0).focus() ' first focus on button
    Wait 2
    wb.Document.getElementsByName("btnK")(0).click() ' then click
    Set wb = Nothing ' clean up
End Sub

 

Remember, the IE tab must be the active window.



-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.



 05/24/2018 05:38 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

PG, I am very grateful for all of your assistance. I can't get anything to work at this point.

 

I wonder if part of the problem is that the websites I'm trying to control are using hidden frames.  Westlaw's code doesn't show frames ... but I think there are hidden frames, because clicking buttons doesn't change the url.  The url stays constant even when I'm clicking through to download cases.

 

And I see references to frames at Google.

 

I think I may have to put this on hold until I have more time to try to get to the bottom of it.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.

 05/24/2018 07:15 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

BTW, Westlaw is a really wierd website. For example, if I try to use KnowBrainer's "Display Numbers" functions, the download buttons I want to click will have different numbers each time.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.



 05/24/2018 07:46 PM
User is offline View Users Profile Print this message

Author Icon
Lunis Orcutt
Top-Tier Member

Posts: 39967
Joined: 10/01/2006

Alex, the DISPLAY Numbers command works the same way on most complex websites, Windows and programs. In other words the numbers change depending on how this feature reads the window so creating a command that utilizes KnowBrainer's DISPLAY Numbers feature, which is available in KnowBrainer VerbalBasic, would unfortunately be unreliable. This feature will work faster in the DPI15 Upgrade, but no better than it does in your current DPI 14. However, if your browser is always kept in the same position or maximized, you could create KnowBrainer mouse commands, which are considered to be a last resort but relatively easy to create. You will find details on this procedure in your VerbalBasic Manual or we can assist you with writing them on your computer virtually.



-------------------------

Change "No" to "Know" w/KnowBrainer 2020
Trial Downloads
Dragon/Sales@KnowBrainer.com 
(615) 884-4558 ex 1

 05/24/2018 07:57 PM
User is offline View Users Profile Print this message

Author Icon
AlexF
Senior Member

Posts: 84
Joined: 11/07/2014

Thank you, Lunis.  Amusingly, even the mouse positions change for the download buttons on the Westlaw website, even though the pop-up boxes would appear to hold a fixed position.  It is horribly programmed for usability.

 

Probably the most sure-fire way to click the buttons is to use a rapid-fire cluster of mouse clicks - including several positions a little above and several a little below the average button position - to make sure that one of them strikes gold.



-------------------------

I'm using KnowBrainer 17 and Dragon Professional Individual version 14.

 05/25/2018 09:42 AM
User is offline View Users Profile Print this message

Author Icon
PG LTU
Top-Tier Member

Posts: 2210
Joined: 03/21/2007

Btw, AlexF, yes, as you noticed, controlling IE by the DOM doesn't work for the stuff served up by AJAX or PHP (and other CMS stacks) because that content is produced dynamically by the browser and is thus not visible to the DOM (which just sees the container, not the content).

There _are_ ways, though. Some tools: First thing, go get yourself the list of keyboard shortcuts and write the scripts to use them. Second, find a "fixed" place that you can focus on, and then count "tabs" to a control you want (if it doesn't change, you can script that). Third, there are tools (I use ahk) that let you figure out what color pixel is under the mouse. You can use this to find buttons or other controls. Lastly, sometimes you can use the location bar to directly enter the javascript or other code that your control wants to send back to the server.

Hth,

-------------------------




PG





Remember folks, my comments and this forum are for entertainment value only, please, no wagering or other reliance on the contents herein.  I permit no commercial use of my ideas (whether expressions or embodiments) without my written consent.

Statistics
32324 users are registered to the KnowBrainer Speech Recognition forum.
There are currently 1 users logged in.
The most users ever online was 12124 on 09/09/2020 at 04:59 AM.
There are currently 332 guests browsing this forum, which makes a total of 333 users using this forum.

FuseTalk Standard Edition v4.0 - © 1999-2022 FuseTalk™ Inc. All rights reserved.