CLICK on button in a web page

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

CLICK on button in a web page

Post by sal21 »

Based this lin k:

https://demo.istat.it/app/?i=D7B&l=it&a=2024

1) click on button: Vista Territoriale
2) click on radio button: Tutti i comuni della provincia selezionata (Seleziona la provincia)
3) click on Listbox mese Luglio
$) click on button Cerca

Appear a table with data.

I need to click on button Esporta in csv, and save the csv file in c:\test\

my test code:

Code: Select all

Dim IE As Object, P1 As Integer, P2 As Integer, I As Integer, TESTO As String
    Dim URL As String, VALORE As String, STRINGA As String
    Dim TB As HTMLTable
    Dim TRO As HTMLTableRow
    Dim TDC As HTMLTableCell
    
    'Dim IE As Object
    Dim oHDoc As HTMLDocument
    
    Set IE = CreateObject("InternetExplorer.Application")
    
    With IE
        .Visible = True
        .navigate "https://demo.istat.it/app/?i=D7B&l=it&a=2024"
    End With
    
    While IE.readyState <> 4
        DoEvents
    Wend
 
    Set oHDoc = IE.document
    
    With oHDoc
        .getElementById("tab-1").Click
        .getElementById("provincerb-1").Click
        .getElementById("btnricerca-1").Click
        .getElementById("dt-button buttons-csv buttons-html5").Click[b]<<<< dont work[/b]
    End With

User avatar
SpeakEasy
5StarLounger
Posts: 634
Joined: 27 Jun 2021, 10:46

Re: CLICK on button in a web page

Post by SpeakEasy »

The iStat site does not work properly on IE, not unsurprising these days.

As a result neither the button with id "dt-button buttons-csv buttons-html5" nor the table you are hoping to export actually exist on the page.

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

Re: CLICK on button in a web page

Post by sal21 »

SpeakEasy wrote:
31 Oct 2024, 12:27
The iStat site does not work properly on IE, not unsurprising these days.

As a result neither the button with id "dt-button buttons-csv buttons-html5" nor the table you are hoping to export actually exist on the page.
I BRO,
If i understand it is not even possible to scrape the table?

User avatar
SpeakEasy
5StarLounger
Posts: 634
Joined: 27 Jun 2021, 10:46

Re: CLICK on button in a web page

Post by SpeakEasy »

If the table isn't there then you cannot scrape it.

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

Re: CLICK on button in a web page

Post by sal21 »

SpeakEasy wrote:
31 Oct 2024, 17:55
If the table isn't there then you cannot scrape it.
SpeakEasy,

Have a simple code to extract from: this class:
<select class="w3-select" name="province" id="province-1" title="Seleziona la provincia" required

all province with the related code, similar:

"084-Agrigento
"006-Alessandria
...
"056-Viterbo

Attached the html page
You do not have the required permissions to view the files attached to this post.

User avatar
SpeakEasy
5StarLounger
Posts: 634
Joined: 27 Jun 2021, 10:46

Re: CLICK on button in a web page

Post by SpeakEasy »

Code: Select all

Public Sub GetJsonData2()
    Dim objHttp As Object
    Dim myHTMLDoc As New HTMLDocument
    Dim SelectOptions As Object
    Dim myOption As Object
    
    Set objHttp = CreateObject("MSXML2.XMLHTTP")
    
    objHttp.Open "POST", "https://demo.istat.it/app/?i=D7B&l=it&a=2024", False
    objHttp.send
    myHTMLDoc.body.innerHTML = objHttp.responseText
     
    Set SelectOptions = myHTMLDoc.getElementById("province-1").Options
    For Each myOption In SelectOptions
        Debug.Print myOption.Value & vbTab & myOption.Text
    Next
End Sub

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

Re: CLICK on button in a web page

Post by sal21 »

SpeakEasy wrote:
02 Nov 2024, 13:47

Code: Select all

Public Sub GetJsonData2()
    Dim objHttp As Object
    Dim myHTMLDoc As New HTMLDocument
    Dim SelectOptions As Object
    Dim myOption As Object
    
    Set objHttp = CreateObject("MSXML2.XMLHTTP")
    
    objHttp.Open "POST", "https://demo.istat.it/app/?i=D7B&l=it&a=2024", False
    objHttp.send
    myHTMLDoc.body.innerHTML = objHttp.responseText
     
    Set SelectOptions = myHTMLDoc.getElementById("province-1").Options
    For Each myOption In SelectOptions
        Debug.Print myOption.Value & vbTab & myOption.Text
    Next
End Sub
i bro...
installed Selenium driver and Cromedriver, this code work perfect on VBA for Excel, but in VB 6.0 have this error (see image) in:

Sub TEST_CHROME()

Dim BOT As New WebDriver
Dim rowc, cc, columnC As Integer
BOT.start "Chrome" '<<<<< error here
BOT.Get "https://demo.istat.it/app/?i=D7B&l=it&a=2024"

BOT.FindElementById("tab-1").SendKeys ("Vista territoriale")
BOT.FindElementById("provincerb-1").SendKeys ("Tutti i comuni della provincia selezionata")
BOT.FindElementById("btnricerca-1").SendKeys("Cerca").Click

End Sub
You do not have the required permissions to view the files attached to this post.

User avatar
SpeakEasy
5StarLounger
Posts: 634
Joined: 27 Jun 2021, 10:46

Re: CLICK on button in a web page

Post by SpeakEasy »

>Selenium driver and Cromedriver, this code work perfect

My code 'work perfect'? My code doesn't require Selenium or Chromedriver.

Or are you posting a new, different problem? In which case you might want to start a new thread so things don't get confusing in this one.

User avatar
sal21
PlatinumLounger
Posts: 4519
Joined: 26 Apr 2010, 17:36

Re: CLICK on button in a web page

Post by sal21 »

SpeakEasy wrote:
04 Nov 2024, 17:31
>Selenium driver and Cromedriver, this code work perfect

My code 'work perfect'? My code doesn't require Selenium or Chromedriver.

Or are you posting a new, different problem? In which case you might want to start a new thread so things don't get confusing in this one.
No your code work perfect.
Tks

But this Is a new question, Sorry.