I want to open a webpage in internet explorer and navigate to a page and click on a button in the page using vbscript.
For example
i I want to open IE and navigate to "http://www.gmail.com",
wait for the page to load,
and fill the username and password into the username and password text boxes and hit the sign in button using VB script.
This was the only thing i could find (only to open a page in IE ) :
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("iexplore.exe www.gmail.com", 1)
please help me out.
Something like:
Set IE = CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "http://mydomain.com/form.asp"
IE.Visible = True
Wscript.Sleep 2000
IE.Document.All.Item("Item1Id").Value = "1000"
IE.Document.All.Item("Item2Id").Value = "1001"
IE.Document.All.Item("Item3Id").Value = "Some Text"
Call IE.Document.Forms(0).Submit()
Related
I have a script that opens a URL in Internet Explorer, enters the username and password and clicks Submit. I can't get past the default Internet Explorer open/save prompt. Is this possible?
Call Main
Function Main
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.blahblahblah.com"
Wait IE
With IE.Document
.getElementByID("ctrluser").value = "blahblahblah"
.getElementByID("ctrlpass").value = "blahblahblah"
.getElementByID("frmSubmit").Click
End With
End Function
Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
End Sub
Also, can you change the default download location to a specific network folder?
I'm using the following code to navigate to a web site and then predetermine the drop downs on the page and it works fine...
Private Sub CommandButton4_Click()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "https://postimage.io/"
IE.Visible = True
While IE.busy
DoEvents
Wend
IE.document.All("optsize").Value = "8"
IE.document.All("expire").Value = "0"
End Sub
... however there is a button on the page Choose images i would like my script to click that and in the pop-up enter a address of an image then press open
is this possible? if so could someone please help me achieve it
I'm creating a macro that will navigate to a login page, log in, navigate to another page and scrape data, and then loop through 100-200 more pages scraping data from each.
So far I've gotten it to the point of logging in, navigating to the second page, and scraping the first bit of data. But so far the only way I can get it to work is if the second page opens in a new window. Since I ultimately have to go through 100-200 pages, I'd rather not use a new window for each one.
For this example let's just say that the only data I'm trying to scrape is the page title.
Option Explicit
Sub admin_scraper()
Dim ie As Object
Dim doc As Object
' Get through log in page
Set ie = CreateObject("internetexplorer.application")
With ie
.navigate "http://example.com/login" 'Page title is "Page 1"
.Visible = True
End With
While ie.Busy Or ie.readyState <> 4
DoEvents
Wend
ie.document.forms(0).all("Username").Value = "user"
ie.document.forms(0).all("Password").Value = "abc123"
ie.document.forms(0).submit
'Navigate to second page and pull page title
Set ie = CreateObject("internetexplorer.application") '***Line in question
With ie
.navigate "http://example.com/Products" 'Page title is "Page 2"
.Visible = True
End With
While ie.Busy Or ie.readyState <> 4
DoEvents
Wend
Set doc = ie.document
Debug.Print doc.Title
End Sub
*** If I include this line the code works as expected (console prints "Page 2"), but it opens the second page in a new window. If I don't include this line, the second page opens smoothly in the same window, but the console prints "Page 1."
Any way I can get it to open each new page in the same window while making sure it pulls data from the new page? Or if it has to be in a new window, any way to automatically close the old window each time?
in my Access & VBA application i Have to get and manage a web page of a web order application. Normally, I use the solution indicated in this post, which normally works perfectly:
VBA Open web page, login and get the opened page
But, now I have another old web application to connect with my Access software. In this web application, after login, the web page closes itself and open an other browser session with the first user page. In other words:
1) The user fill the login form with the user credentials
2) After login, the login web page closes the browser
3) An other browser session opens with the web app control panel
If I use the linked solution, I see an error. How can I get the new web page, in the new browser session, which opens it self after login?
Thanks!
EDIT
I have tried the following code (my purpose is set a text value in the web page). But, very strange, it works only if I put a text box in my code: maybe the code must wait some event! How can I solve it?
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 10, DateTime.Now)
Dim ieA As InternetExplorer
Dim IeDocA As HTMLDocument
Do While dt > DateTime.Now
Set winShell = New Shell
For Each ieA In winShell.Windows
If ieA.LocationURL = sURL Then
ieA.Visible = True
ieA.Silent = True
Do While ieA.Busy: DoEvents: Loop
Do Until ieA.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set IeDocA = ieA.Document
//only with this msgbox it works, how can I do this w/out it?
MsgBox IeDocA.title
With IeDocA
.getElementsByName("text").value="something"
End With
Set winShell = Nothing
Exit Do
End If
Next ieA
Set winShell = Nothing
DoEvents
Loop
You can Look for the URL in the window. You will need a reference to Microsoft Shell Controls and Automation.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Desc: The Function gets the Internet Explorer window that has the current
' URL from the sURL Parameter. The Function Timesout after 30 seconds
'Input parameters:
'String sURL - The URL to look for
'Output parameters:
'InternetExplorer ie - the Internet Explorer window holding the webpage
'Result: returns the the Internet Explorer window holding the webpage
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetWebPage(sUrl As String) As InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 30, DateTime.Now)
Dim ie As InternetExplorer
Do While dt > DateTime.Now
Set winShell = New Shell
'loop through the windows and check the internet explorer windows
For Each ie In winShell.Windows
'check the URL
If ie.LocationURL = sUrl Then
'set some properties
ie.Visible = True
ie.Silent = True
Set GetWebPage = ie
'loop while IE is busy
Do While ie.Busy
DoEvents
Loop
Set winShell = Nothing
Exit Do
End If
Next ie
Set winShell = Nothing
DoEvents
Loop
End Function
I have this situation that I'm struggling to solve without any luck. I use VBA in Excel to navigate to a website. On this website, I use VBA to click on a div with id id-01, which works fine. Clicking on that div#id-01 will generate another div with id id-02, I want to click on this div. How can I click on the div with id-02 with VBA?
Set IE = CreateObject("InternetExplorer.Application")
'
'code to navigate to site and wait for site to load
'
'Get div#id-01 and click on it
Set first = IE.document.getElementById("id-01")
'click it
first.click
'The following code does not work because
Set second = IE.document.getElementById("id-02")
second.click
I generally reset the document after the new element has been added by the first.
Try this:
Set IE = CreateObject("InternetExplorer.Application")
'
'code to navigate to site and wait for site to load
'
set myDoc = IE.Document
Set first = myDoc.getElementById("id-01")
'click it
first.click
(WAIT 2 seconds)
set myDoc = IE.Document
Set second = IE.document.getElementById("id-02")
second.click[/code]