I want to code to click a menu in a website.
Sub SearchBot()
Dim ie As Object
Dim HTMLDoc As MSHTML.HTMLDocument
Dim ckt_No As String
ckt_No = Range("A2").Value
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ShowWindow ie.hwnd, SW_MAXIMIZE
ie.Navigate "http://gamit.web.att.com/gamitx/welcome.htm"
Do While ie.Busy = True Or ie.ReadyState <> 4: DoEvents: Loop
Set HTMLDoc = ie.Document
HTMLDoc.getElementById("yui-gen1").Focus
HTMLDoc.getElementById("yui-gen1").Click
Do While ie.Busy = True Or ie.ReadyState <> 4: DoEvents: Loop
Stop 'Press SHIFT + F9 and examine the window...
The menu
while inspect the menu I got the HTML Code
VBA didn't throw any error, but it does not click the menu.
After running the code the menu looks like this
I have Microsoft Internet control, Microsoft HTML object library functions in my VBA editor.
Try navigating to the href of the child a tag (getting the parent by its id)
ie.navigate2 HTMLDoc.querySelector("#yui-gen1 a").href
Maybe this, but I can't test it as your url is not working for me
HTMLDoc.getElementById("yui-gen1").nextPageElement.Click
Related
I am a beginner and non-technical person, I am completely stuck here
I want to click the New Project button using VBA
Here is the inspect Element for New project button
<button tabindex="0" class="xui-button xui-button-create xui-button-small" type="button" data-automationid="project-modal-new-button">New project</button>
Below is the code, I have created so far, it's running without any issues and it will take me to the project tab from the Project Tab I need to click the new Project Button using VBA
Sub Xero()
Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True
i.navigate ("https://login.xero.com/")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = i.document
idoc.all.UserName.Value = "XXXXX"
idoc.all.Password.Value = "123"
Dim ele As MSHTML.IHTMLElement
Dim eles As MSHTML.IHTMLElementCollection
Set eles = idoc.getElementsByTagName("button")
For Each ele In eles
If ele.ID = "submitButton" Then
ele.Click
Application.Wait (Now + TimeValue("0:00:10"))
Else
End If
Next ele
i.navigate ("https://projects.xero.com/?CID=!QhJgj")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
End Sub
I want to click the New project button to move further
Try using a css class selector (same idea as getElementsByClassName but faster)
While i.Busy Or i.readyState < 4: DoEvents: Wend
Application.Wait Now + Timeserial(0,0,2)
i.document.querySelector(".xui-button-create").click
Also, use proper page waits after .click and .navigate i.e.
While i.Busy Or i.readyState < 4: DoEvents: Wend
So, have that proper wait between .navigate and the attempt to click the button and again after clicking the button.
I am working on a web form fill using excel cells data, and the issue here is that after filling the text in the first page using the elements ID, when it click on Submit it loads a new IE.
Now here I am not able to fill the text using the elements ID etc, as its (VBA) not identifying it or not considering it.
IE Page loads properly here no issue.
Sub Test1()
Dim IE As Object
Dim doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://xyzfrmTarget=New&Text_ident=002719&frmOption=CREATE"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
'IE.document.getElementById().Value="test"
'doc.getElementById("ui-new_widget-1_new_company_12").Value = ThisWorkbook.Sheets("Data").Range("A2").Value
doc.getElementById("ui-new_widget-1_monitor_12").Value = ThisWorkbook.Sheets("Data").Range("A2").Value
doc.getElementById("new_date").Value = "2019-01-19"
'ThisWorkbook.Sheets("Data").Range("c2").Value
doc.getElementById("new_no_mail").Click
IE.document.forms(0).submit
End Sub
It submit the 1st page with the Text data from excel, but issue with the 2nd page which loads
Try using proper waits after navigate and .click and work off .document. This should update with new content after the .click
Option Explicit
Public Sub PerformActions()
Dim IE As InternetExplorer
Set IE = New InternetExplorer
With IE
.Visible = True
.Navigate2 "https://xyzfrmTarget=New&Text_ident=002719&frmOption=CREATE"
While .Busy Or .readyState < 4: DoEvents: Wend
.document.getElementById("ui-new_widget-1_monitor_12").Value = ThisWorkbook.Sheets("Data").Range("A2").Value
.document.getElementById("new_date").Value = "2019-01-19"
.document.getElementById("new_no_mail").Click
While .Busy Or .readyState < 4: DoEvents: Wend
'.document ''< do whatever references off .document here
'other code
'.quit
End With
End Sub
so I'm trying to learn how to interact with html using vba and I'm using this code:
Sub IEScraper()
Dim ie As InternetExplorer
Dim link As HTMLLinkElement
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate ("duckduckgo.com")
Do While ie.Busy = True Or ie.READYSTATE <> 4
DoEvents
Loop
ie.document.getElementById("search_form_input_homepage").Value = _
Sheets(1).Range("A1").Value
ie.document.getElementById("search_form_input_homepage").Click
End Sub
It works up until the click line, where the page just won't click. No error pops up and the code ends but the button won't be clicked. Is there something I'm doing wrong?
try
ie.document.getElementById("search_button_homepage").Click
I am trying to copy the response from the website, but I have to select one of the options from the dropdown list so the page can refresh.
So far, I've managed to open IE and click the dropdown button, but I cannot select the option, don't know why. Please find the a sample of the code below.
Sub OpenWebSelectClickSaveHtmlFile()
Dim URL As String
URL = "http://formulaacademia.com.br/academia"
Set myIE = CreateObject("InternetExplorer.Application")
With myIE
.navigate URL
.Visible = True
Do While .Busy = True Or .readyState <> 4
Loop
DoEvents
Set selectitems = myIE.document.getElementsByTagName("button")
For Each i In selectitems
i.Click
Next i
End With
End Sub
Rgds
It should be something like this. Change the relevant parts to suit your needs.
Sub passValueToComboBox1()
Dim ie As Object
Dim oHTML_Element As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://peterschleif.bplaced.net/excel/combobox/index.php"
While ie.Busy Or ie.readyState <> 4: DoEvents: Wend
Set oHTML_Element = ie.document.getElementsByName("selectedReportClass")(0)
If Not oHTML_Element Is Nothing Then oHTML_Element.Value = "com.db.moap.report.FUBU7"
For Each oHTML_Element In ie.document.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
End Sub
I want to click a button on a website with VBA and extract the table which appears when clicked.
My code is here but it is not working right now, how can I do that?
I want to click the "Get Price Quoted" button on the right corner of the table and extract appearing information.
Sub Test()
Dim IE As Object
Dim doc As Object
Dim strURL As String
Dim objElement As Object
Dim objCollection As Object
strURL = "http://financials.morningstar.com/competitors/industry-peer.action?t=GOOG®ion=usa&culture=en-US"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate strURL
Do Until .ReadyState = 4: DoEvents: Loop
Do While .Busy: DoEvents: Loop
Dim Item As Object
Set Item = IE.document.getElementsByClassName("hspacer0")
Item.Item(0).Click
Do Until .ReadyState = 4: DoEvents: Loop
Do While .Busy: DoEvents: Loop
Set doc = IE.document
GetAllTables6 doc
.Quit
End With
End Sub
You are not clicking the correct button the code. I am not sure what button if any you are clicking. But if you run the javascript code loadIndustryPeersQuoteData(1) it will 'click' the button and then you will need to code getting the table.
That 'hspacer0' is just a blank spacer that contains no objects or anything to click.