I have some code that used to work fine, but for some reason it has stopped selecting the tab that says "your leagues".
The code pulls live football scores into excel.
The only bit I need help with is where I need to navigate from all games to your leagues (the code does not recognize the button and so is not clicking it). Any help will be appreciated. Thanks.
'Define Variables
url = "http://www.futbol24.com/Live/livenow/"
'Open url
ie.Visible = False
ie.Navigate url
frmbusy.lbstatus.AddItem "Navigating to Web Page"
busywait
'Navigate from ALL Games to Your Leagues
Set tagname = ie.Document.getelementsbytagname("*")
For z = 0 To tagname.Length - 1
If tagname(z).ID = "f24com_i18n_btnChooseLeague_your" Then
tagname(z).Click
busywait
End If
Next
You can use a querySelector to target
#f24com_btnChooseLeague_choose > a > span
This is the span tag within an a tag with element with id #f24com_btnChooseLeague_choose
You can shorten this simply to #f24com_btnChooseLeague_choose > a
Option Explicit
Public Sub ClickChooseLeagues()
Dim ie As New InternetExplorer
With ie
.Visible = True
.navigate "https://www.futbol24.com/Live/livenow/"
While .Busy Or .readyState < 4: DoEvents: Wend
.document.querySelector("#f24com_btnChooseLeague_choose > a").Click
Stop
End With
End Sub
Related
I need to loop through a dropdown list of a specific website and download the latest file for each entry. I managed to open the website and click the "submit" button, but I can´t find a solution to loop through all the dropdown entries.
Dim reportnr As String
Dim internetadress As String
Dim btn As Object
Dim IE As SHDocVw.InternetExplorer
reportnr = 10
internetadress = adress & reportnr
Set IE = CreateObject('InternetExplorer.Application')
IE.Visible = True
IE.navigate internetadress
Do While IE.Busy
Application.Wait DateAdd("s", 2, Now)
Loop
While IE.Busy
DoEvents
Wend
For Each btn In IE.document.getElementsByClassName("btn btn-primary")
If btn.name = "submit" Then
btn.Click
End If
Next btn
The code on the website regarding the dropdown below.
I tried several approchoaches, but I´ll get error or just nothing happens. Last thing I tried is this :
Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls
Public Sub SelectQuantity()
Dim ie As New InternetExplorer, numberOfOptions As Long, i As Long
With ie
.Visible = True
.Navigate2 "https://www.amazon.com/belif-True-Cream-Aqua-Korean/dp/B00H4GOAZO/ref=pd_cart_crc_cko_cp_2_2/139-8277217-3794320?_encoding=UTF8&pd_rd_i=B00H4GOAZO&pd_rd_r=e154e278-8a11-4ab0-8173-5d0dbaff1938&pd_rd_w=Hm8FW&pd_rd_wg=Hpv4X&pf_rd_p=eff166ab-25d2-4f2c-a51d-0a0e86061f9d&pf_rd_r=EVT26E6K7CV8T1QMTY7H&psc=1&refRID=EVT26E6K7CV8T1QMTY7H"
While .Busy Or .readyState < 4: DoEvents: Wend
With .document
numberOfOptions = .querySelectorAll("#quantity option").Length 'gather option tag element children of parent select element with id quantity
For i = 1 To numberOfOptions
.querySelector("#quantity [value='" & i & "']").Selected = True
ActiveSheet.Cells(i, 1) = i
Next
Stop
End With
End With
End Sub
Source: VBA loop through dropdown elements from web page and download to excel sheet
Thanks in advance for help.
From the website you provide, you can try the following code to loop through the dropdown list to choose the option you want:
Set lists = IE.document.getElementsByClassName("active-result") 'get all the options li elements
For Each liElement In lists
If liElement.innerText = "something" Then
liElement.setAttribute "class", "active-result result-selected"
End If
Next liElement
I find that the chosen option has different class which is active-result result-selected, so I think maybe you can change the class to select the option.
I tried to extract somes information from ALibaba.com but i didn't success to select Supplier in the list
Here is the html code
Set Post = IEdoc_ALi.getElementsByClassName("ui-searchbar-type-option").Item
Post.all(2).innerText = "Suppliers"
Thanks in advance
It's a link that needs clicking. You can use a css attribute = value selector to target the relevant node and then apply the click method.
Option Explicit
Public Sub SelectSuppliers()
Dim ie As SHDocVw.InternetExplorer
Set ie = New SHDocVw.InternetExplorer
With ie
.Visible = True
.Navigate2 "https://www.alibaba.com/"
While .Busy Or .readyState <> 4: DoEvents: Wend
.document.querySelector("[data-value=suppliers]").Click
Stop '<Delete me later
End With
End Sub
I would like to know what the best syntax would be to click the"send to" button on the web page.
Here's the code so far:
Option Explicit
Sub Search_PubMedandCochrane()
Dim IE As New SHDocVw.InternetExplorer
IE.Visible = True
IE.Navigate "https://www.ncbi.nlm.nih.gov/pubmed"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Debug.Print IE.LocationName, IE.LocationURL
IE.Document.forms("EntrezForm").elements("term").Value = Range("B4")
IE.Document.forms("EntrezForm").elements("search").Click
End Sub
Try an attribute = value CSS selector to target the element by an attribute and its value.
IE.document.querySelector("[sourcecontent='send_to_menu']").click
Make sure you have a sufficient page load wait before trying to click. As a minimum you need
While IE.Busy Or IE.readyState < 4: DoEvents: Wend
IE.document.querySelector("[sourcecontent='send_to_menu']").click
You could also use
IE.document.querySelector("#sendto > a").click
I have this simple macro that opens up IE and type a word in search box. It was working before, but now is returning
Error 424 - Object required.
Any ideas on what is happening? Is there any lib reference that I'm missing?
Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate ("https://www.google.com/")
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Set xobj = ie.document.getElementById("lst-ib")
Call xobj.setAttribute("value", "teste")
End Sub
That id doesn't appear against the input box when I open google. You can use an attribute = value selector to target the title attribute of the search box. Right-click inspect the search box and see what your local language attribute value is for title=. In U.K. the value is Search. Use whatever your local value is.
Element html:
Other:
Also, .navigate2 is the preferred method.
If the page is slow loading you may need a loop until element present.
Option Explicit
Public Sub AcessaPaginaDados()
Dim xobj As HTMLDivElement
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate2 "https://www.google.com/"
While .Busy Or .readyState < 4: DoEvents: Wend
Set xobj = .document.querySelector("[title=Search]")
xobj.Value = "teste"
Stop
.Quit
End With
End Sub
I am quite new to VBA/html, trying to automate filling a form, but cannot even call it ... I searched the web for weeks tried many different code combinations, but none got me there.
The HTML code/element looks like this:
div title:"TextText" class:"text-truncate mb-2" id="abc_sidebar_startmenuitem" data-type="record" data-appid="82" data url="index.cfm?Xxx=&Yyy=">
i class="fa icon-app-82 mr-1 fa-fw">/i>
span class="clickable" id="ext-eng123">Text/span>
/div>
Problem is that class="clickable" is 30th appearance of clickable on the page, id="ext-eng123" is built from the text ext-eng and 3 variable unknown digits, always different.
Example of VBA code used:
Sub GetClick()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate "https://company.application.com/home/index.cfm?Tab=home"
Do While .Busy
DoEvents
Loop
Do While .readyState <> 4
DoEvents
Loop
End With
Dim objIE As Object
objIE = document.getElementByClassName("clickable")(29)
objIE.Click
End Sub
I tried over 10+ different code samples, including calling frame number, none worked, I am stuck.
Try the following code. It is hard to give any solution without playing with that site. They are always hypothetical.
Sub GetClick()
Dim IE As New InternetExplorer, Html As HTMLDocument
With IE
.Visible = True
.Navigate "https://company.application.com/home/index.cfm?Tab=home"
While .Busy = True Or .ReadyState < 4: DoEvents: Wend
Set Html = .Document
End With
''If the problem still persists, make sure to put here some delay
Html.querySelector(".clickable[id^='ext-eng']").Click
End Sub
Another approach might be something like (if the word "Text" didn't appear anywhere with the same class name):
For Each elem In Html.getElementsByClassName("clickable")
If InStr(elem.innerText, "Text") > 0 Then elem.Click: Exit For
Next elem
Reference to add:
Microsoft Internet Controls
Microsoft HTML Object Library