I have code which picks up data from multiple columns from ThisWorkbook and puts in various field in website in internet explorer. The website loads after clicking on line1 (Search button). Then the code throws an error at line2 where it clicks on checkbox, as there is no checkbox yet if the website is still loading. (I think the website is built on Sharepoint and is poorly coded.)
Is there any code which repeats line 2 after 2-3 seconds and continues further whenever the error appears? I tried error handler to repeat the code but didn't work.
Sub CSA_Upload()
Dim test1 As Long, test2 As Long
test1 = Timer
Dim n As Long
Range("A1").Select
n = Selection.End(xlDown).Row
ThisWorkbook.Sheets("Data").Range("A2:A" & n).Interior.ColorIndex = 0
Dim IE As Object
Dim doc As Object
Dim htmlTable As htmlTable
Set IE = New InternetExplorerMedium
'Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'Navigate to CSA tool Home Page
IE.navigate "https://csa.abcdefg.com/Collector_view.aspx/"
'Wait till it loads
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = CreateObject("htmlfile")
Set doc = IE.document
'Enter Invoice Number in SearchBy box
doc.getElementById("ContentPlaceHolder1_ddlSearch").Value = "[Inv Number]"
Range("A1").Select
'Count the number of rows in the data list
Dim X As Long
Range("A1").Select
X = Selection.End(xlDown).Row
'For each invoice number the loop starts here
For rowNo = 2 To X
ActiveCell.Offset(1).Select
'Fill Blue colour in active processing invoice number cell
ThisWorkbook.Sheets("Data").Range("A" & rowNo).Interior.ColorIndex = 37
'Input the invoice number
doc.getElementById("ContentPlaceHolder1_txtSearch").Value = ThisWorkbook.Sheets("Data").Range("A" & rowNo).Value
'Click the Search button
'This is the Line1
doc.getElementById("ContentPlaceHolder1_search").Click
'Wait till it loads
Do While IE.Busy
Application.Wait DateAdd("s", 5, Now)
Loop
'Checkbox select all
'This is the Line2
doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll").Click
'Wait 3 seconds till it selects all the checkboxes
Application.Wait DateAdd("s", 3, Now)
'Enter rest of the data
doc.getElementById("ContentPlaceHolder1_ddlaction").Value = ThisWorkbook.Sheets("Data").Range("B" & rowNo).Value 'Input Action
doc.getElementById("ContentPlaceHolder1_txtToDoDate").Value = ThisWorkbook.Sheets("Data").Range("C" & rowNo).Value 'Input Action Date
doc.getElementById("ContentPlaceHolder1_ddlstatus").Value = ThisWorkbook.Sheets("Data").Range("D" & rowNo).Value 'Input Root Cause
doc.getElementById("ContentPlaceHolder1_txtcomments").Value = ThisWorkbook.Sheets("Data").Range("E" & rowNo).Value 'Input Comments
doc.getElementById("ContentPlaceHolder1_btn_Comments").Click 'Click Submit button
Application.Wait DateAdd("s", 3, Now)
'Hit enter on MessegeBox
Application.SendKeys "{ENTER}"
'Fill Green colour in the active cell when all entries are passed
ThisWorkbook.Sheets("Data").Range("A" & rowNo).Interior.ColorIndex = 35
Next 'Proceed to next invoice number
IE.Quit 'Quit Internet explorer
test2 = Timer
MsgBox (X - 1) & " Invoices have been updated and it took " & Format((test2 - test1) / 86400, "hh:mm:ss") & " Seconds."
End Sub
revised on 2019-03-25
I think the error is thrown because the doc is changed.
Rewrite
' This is the Line2
doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll").Click
'Wait 3 seconds till it selects all the checkboxes
Application.Wait DateAdd("s", 3, Now)
as
' This is the Line2
application.wait Application.Wait DateAdd("s", 1, Now)
set doc = IE.document
doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll").Click
'Wait 3 seconds till it selects all the checkboxes
Application.Wait DateAdd("s", 3, Now)
maybe helpful.
Use proper page load waits after each .Navigate and .Click.
While ie.Busy Or ie.readyState < 4: DoEvents: Wend
Also, you can wrap elements that are throwing errors, related to timings, in timed loops which attempt to set the object reference
Dim t As Date, ele As Object
Const MAX_WAIT_SEC As Long = 10
t = Timer
Do
On Error Resume Next
Set ele = doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While ele Is Nothing
If Not ele Is Nothing Then
ele.Click
End If
I have removed below wait loop after line 1.
'Wait till it loads
Do While IE.Busy
Application.Wait DateAdd("s", 5, Now)
Loop
and added fix 10 seconds wait time Application.Wait DateAdd("s", 10, Now) just before
doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll").Click
'Wait 3 seconds till it selects all the checkboxes
Application.Wait DateAdd("s", 3, Now)
So the final piece of code is as below and it's working!
'This is the Line1
doc.getElementById("ContentPlaceHolder1_search").Click
'Checkbox select all
'This is the Line2
Application.Wait DateAdd("s", 10, Now)
doc.getElementById("ContentPlaceHolder1_GridView1_chkboxSelectAll").Click
'Wait 3 seconds till it selects all the checkboxes
Application.Wait DateAdd("s", 3, Now)
Related
It's my first question and I'm new on VBA.
I was trying to run a macro to automatize some procedures on IE. My macro worked very well when opened on diferent windows, but when I tried to run the same macro on tabs it didn't work. It seems (maybe) the macro isn't recognizing the actual tab. Could anyone help me, please?
Sub Test1()
Dim IE As Object
Dim doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
For intRow = 1 To 3
If intRow = 1 Then
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp"
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
IE.document.getElementById("principal").Children(4). _
getElementsByTagName("tbody")(0).getElementsByTagName("tr")(5). _
getElementsByTagName("td")(1).getElementsByTagName("font")(0). _
getElementsByTagName("input")(0).Value = "intRow"
Application.Wait DateAdd("s", 2, Now)
End With
Else
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp", 2048&
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
.document.getElementById("principal").Children(4). _
getElementsByTagName("tbody")(0).getElementsByTagName("tr")(5). _
getElementsByTagName("td")(1).getElementsByTagName("font")(0). _
getElementsByTagName("input")(0).Value = "intRow"
Application.Wait DateAdd("s", 2, Now)
End With
End If
Next
End Sub
According to your code and the website, it seems that you want to open multiple tab (with the same URL), and then fill a value in the text box. We should pay attention to the following point:
How to access the web page elements.
How to switch tabs and focus to the new tab.
To access the web page elements, from your web page resource (use F12 developer tools to check it), I notice that the table contains 6 rows, but the last row doesn't contain the input element. So, using your code, I can't find the input element. I found that the input elements contain the class property. So, I suggest you could use the getElementsByClassName method to find the element.
To switch the IE browser tab, we could loop through the opened tabs and compare the URL, and then set focus on the related tab.
More detail steps, please check the following sample code:
Sub Test1()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Dim intRow As Integer
For intRow = 1 To 3
If intRow = 1 Then
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp"
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
IE.document.getElementsByClassName("basic")(0).Value = "intRow" & intRow
Application.Wait DateAdd("s", 3, Now)
End With
Else
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp", 2048&
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Application.Wait DateAdd("s", 3, Now)
Set IE = GetIE("https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp")
Application.Wait DateAdd("s", 3, Now)
IE.document.getElementsByClassName("basic")(0).Value = "intRow" & intRow
End With
End If
Next
End Sub
Function GetIE(sLocation As String) As Object
Dim retVal As Object
Dim my_url As String, my_title As String
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
'loop through the window and find the tab
For x = 0 To (IE_count - 1)
On Error Resume Next
'get the location and title
my_url = objShell.Windows(x).document.Location
my_title = objShell.Windows(x).document.Title
'debug to check the value
Debug.Print x
Debug.Print my_url
'find the special tab based on the title.
If my_url Like sLocation Then
Set retVal = objShell.Windows(x)
'IE.Quit 'call the Quit method to close the tab.
'Exit For 'exit the for loop
Else
End If
Next
Set GetIE = retVal
End Function
After running the above script, it will open three tabs and fill a value in the Login input text. Please see the following screenshot:
Reference:
Common VBA Methods & Properties used in web automation
I'm new here and on VBA, it's my 2nd post and I don't speak english very well. So, please, take easy on me =D
Last week I was having some troubles trying to automatize some procedures on IE. My macro worked very well when opened on new windows, but when I tried to run the same macro on tabs it wasn't working. It seemed (maybe) the macro wasn't recognizing the actual tab. I post that problem here and a wonderfull guy called Deepak-MSFT helped me a lot. He taught me how to run the macro on tabs and it worked almost 100%.
Problems:
1 - The macro sometimes work, sometimes doesn't. Yesterday, for example, I was getting errors 424, 91 and, sometimes, it just opened another tab without insert the value (perheaps because of the "On Error Resume Next"). I think it was because one of the websites was slow. I tried to increase the TimeValue until 7 seconds but, even so, it didn't work. I tested during the whole day and it was extremely unstable, sometimes worked, and somtimes it doesn't. But today it's working (all the websites are stable). Any idea how to solve this instability?
2 - There are 2 websites (2nd and 3rd) where I use querySelector to find the box to insert the value. Both of them work on 70% of the PC's of my company and only those 2 websites doesn't work on the other 30%. I installed the same version of IE (11.0.9600), Excel (2007, SP3) and Windows (W7) on all of them, but even so, only those 2 websites with queryselector don't work. There are no errors. The macro just don't insert the value. Perhaps I'm missing something that make queryselector works on those PC's, but all the references match. I dig the first 5 pages on google trying to find a solution but I failed. I think there's a witch flying around those PC's. Could you help me?
3 - I have total instability trying to run my macros on Excel 2016 or other versions of Excel higher than 2007 at Windows 10. Does anyone have a good solution to adapt the program to run on Excel 2016 (all my company will run this version next year) without have to do all over again?
Thank you very much guys. Here is my code:
Sub ademo()
Dim i As Long
Dim URL As String
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'TAB 1
URL = "https://servicos.ibama.gov.br/ctf/publico/areasembargadas/ConsultaPublicaAreasEmbargadas.php"
IE.Navigate2 URL
Do While IE.readyState = 4: DoEvents: Loop 'Do While
Do Until IE.readyState = 4: DoEvents: Loop 'Do Until
IE.document.getElementById("num_cpf_cnpj").Value = "demo1" 'Sheets("Main").Range("C10")
IE.document.getElementById("Emitir_Certificado").Click
'TAB 2 - DAP
On Error Resume Next
IE.Visible = True
IE.Navigate2 "http://smap14.mda.gov.br/extratodap/", 2048&
Application.Wait (Now + TimeValue("0:00:04"))
Set IE = GetIE("http://smap14.mda.gov.br/extratodap/")
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
On Error Resume Next
Set Target = IE.document.querySelector("#corpo > div > div > div:nth-child(1) > button")
Target.Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
doc.getElementById("txtCPF_CNPJ").Value = "demo2"
'TAB 3 - CNDT
IE.Visible = True
On Error Resume Next
IE.Navigate2 "http://aplicacao.jt.jus.br/cndtCertidao/inicio.faces", 2048&
Application.Wait (Now + TimeValue("0:00:04"))
Set IE = GetIE("http://aplicacao.jt.jus.br/cndtCertidao/inicio.faces")
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
On Error Resume Next
Set target2 = IE.document.querySelector("#corpo > div > div:nth-child(2) > input:nth-child(1)")
target2.Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
doc.getElementById("gerarCertidaoForm:cpfCnpj").Value = "demo3"
'TAB 4 - CND
On Error Resume Next
IE.Visible = True
IE.Navigate2 "http://servicos.receita.fazenda.gov.br/Servicos/certidao/CNDConjuntaInter/InformaNICertidao.asp?tipo=2", 2048&
Application.Wait (Now + TimeValue("0:00:04"))
Set IE = GetIE("http://servicos.receita.fazenda.gov.br/Servicos/certidao/CNDConjuntaInter/InformaNICertidao.asp?tipo=2")
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
On Error Resume Next
IE.document.getElementsByName("NI")(0).Value = "demo4"
'TAB 5 - IMPROBIDADE
IE.Visible = True
IE.Navigate2 "http://www.cnj.jus.br/improbidade_adm/consultar_requerido.php?validar=form", 2048&
Application.Wait (Now + TimeValue("0:00:04"))
Set IE = GetIE("http://www.cnj.jus.br/improbidade_adm/consultar_requerido.php?validar=form")
IE.document.getElementById("num_cpf_cnpj").Value = "demo5"
End Sub
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
On Error Resume Next 'because may not have a "document" property
'Check the URL and if it's the one you want then
' assign the window object to the return value and exit the loop
sURL = o.document.Location
On Error GoTo 0
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o
Set GetIE = retVal
End Function
I am trying to Right click on Google Maps page, So far I am able to create the object ie, navigate to the page and search for a particular address.
But in the next step I have to click on the bottom of Address marker (Blue Dot)
After the click, I want to select What's Here from the options.
After the selection, I use the line
ie.document.getElementsByClassName("link-like widget-reveal-card-lat-lng")(0).innerText to get the co-ordinates of the Place.
Code so Far:
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "https://www.google.com/maps"
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Application.Wait DateAdd("s", 1, Now)
ie.document.getElementById("searchboxinput").Value = "Signature Tower GurGaon"
ie.document.getElementById("searchbox-searchbutton").Click
MsgBox "After Manually clicking What's Here, press ok"
Basically I want to automate that Manual part. What are the elements that needs to be clicked for the right click and how do I identify the point where to click.
Alternate:
Just found that, those lat-long are also part of the a href by
ie.document.getElementsByClassName("gb_9d gb_2 gb_ob")(0).href
So there is no need to right click.
But I am still interested to know how to Right Click it.
Note that you can put the search term directly into the first navigate.
IE.navigate "https://www.google.com/maps" & "/search/Signature Tower GurGaon"
Your wait loop should check .Busy and .ReadyState
Do While IE.Busy Or IE.ReadyState <> 4
And as you already found out the coordinates are in the source code
Option Explicit
Public Sub Test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.google.com/maps" & "/search/Signature Tower GurGaon"
Do While IE.Busy Or IE.ReadyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Application.Wait DateAdd("s", 1, Now)
Dim GetLocation As String
GetLocation = IE.document.getElementsByClassName("gb_9d gb_2 gb_ob")(0).href
GetLocation = Right$(GetLocation, Len(GetLocation) - InStr(1, GetLocation, "%40") - 2)
GetLocation = Left$(GetLocation, InStr(1, GetLocation, "&") - 1)
Dim Location() As String
Location = Split(GetLocation, "%2C")
Debug.Print "Lat", Location(0)
Debug.Print "Lon", Location(1)
Debug.Print "zoom", Location(2)
End Sub
Will result in
Lat 28.4636862
Lon 77.054257
zoom 16z
I have a macro that connects to a web-page, gets some info and displays it on a user form (for further actions):
Private Sub UserForm_Initialize()
Dim login As String, password As String
Dim waittime As String
Dim arrForms As Variant
Dim ie As InternetExplorer
LoadingForm.Show vbModeless
LoadingForm.lblLoading.Caption = "Loading..."
waittime = "0:00:02"
login = "lgn"
password = "passwrd"
txtEndDate.Value = Format(Now(), "dd.mm.yyyy")
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
'open login page
ie.navigate "my link (internal company database)"
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue(waittime))
'if already logged in, skip
On Error GoTo Skip_login
ie.document.getElementById("_58_login").Value = login
ie.document.getElementById("_58_password").Value = password
ie.document.getElementsByClassName("btn btn-primary")(0).Click
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue(waittime))
Skip_login:
ie.navigate "my link (internal company database)"
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue(waittime))
arrForms = GetListOfForms(ie) 'this is a function that reads the page,
'finds a table and converts its values to an array
'I tried to comment this line (maybe a bug in my function)
'but even without it the code does not work
For i = LBound(arrForms) To UBound(arrForms)
FormsList.AddItem (arrForms(i))
Next i
'Log out and quit IE
ie.navigate "my link (internal company database)"
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue(waittime))
ie.document.getElementById("sign-out").Click
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
Application.Wait (Now + TimeValue(waittime))
ie.Quit
LoadingForm.Hide
End Sub
It worked fine for a few days. It also worked today. But it stopped working for an unknown reason (it just says"automation error" without reference to an error in my code). I was using it, closed the user form, then clicked to start macro again and it does not work. I tried to open older backups - they stopped working too. I did not change anything (links, login/password, any other line of code).
My user form does not have any uncommon user controls. It has the following controls only: text fields, lables, frames, listbox, and buttons)
Good Day, I am developing a tool to scrape 'One-Way fees' off various websites. For a particular website, I am at a stage where I can navigate to the correct page but I cannot figure out how to scrape the One-way fee into excel. I also have an issue where I cant seem to click the 'back' button. My code "works" in that if you iterate through the script by pressing F8 you get to where you need to be. It sometimes falls over at the 'carclick.item(x).click part' if you run it normally. Please note that the One-way fee does not always appear. Its most likely to appear when the pickup and dropoff locations are different. The tasks my code needs to execute is as follows:
create the html object, then open the website.
Click the 'return vehicle to a different location' button to allow the code to access different drop-off locations.
I have ignored drop-off/pick-up times and dates for now as they do not affect the one-way fee and the website default values are adequate. (Also, I couldn't get that to work either)
The code then inputs two locations: one for pickup and one for drop-off.
The code then clicks the 'find vehicle' button. The page loads for a while.
This page shows multiple vehicle options. Each car block may have a 'book' or 'request only' button that needs to be clicked (highlighted in blue), after which, a new page opens revealing the one-way fee. (1315.79 in value for the example values in my code)
The code would then need scape the value and paste it into excel along with the car name and car group (usually a letter of the alphabet).
I would then need to click the 'back' button to get back to the vehicle choices and repeat for all car groups.
The tool needs to then repeat this whole process for all location combinations( the one-way fee may be different even for same location trips but in opposite direction). I haven't got this far as I've been struggling. I really need help with step 7 and 8.
Private Sub test1()
Dim appIE As Object
Dim ws As Worksheet
Dim wb As Workbook
Dim a As String
Dim b As String
Dim c As String
Dim x As Integer
Dim d As String
Dim e As Object
Dim l As Object
Dim PickUp As Object
Dim iL As IHTMLElement 'this declares the html object
Dim f As IHTMLElementCollection ' this declares the collection of html objects
Dim post As Object
Dim Ret As Object
Dim entry As Object
Dim pd As Object
Dim backbutton As Object
Dim carclick As Object
Set wb = Application.Workbooks("Hertz")
Set ws = wb.Worksheets("One Way Fees")
Set appIE = CreateObject("InternetExplorer.application")
With appIE
.Navigate "https://www.Hertz.co.za"
.Visible = True
Application.Wait (Now + TimeValue("0:00:03"))
Do While appIE.Busy
DoEvents
Application.Wait (Now + TimeValue("0:00:03"))
Loop
Application.Wait (Now + TimeValue("0:00:03"))
Set g = appIE.document.getElementById("return-location")
g.Click
Application.Wait (Now + TimeValue("0:00:03"))
Do While appIE.Busy
DoEvents
Application.Wait (Now + TimeValue("0:00:03"))
Loop
Application.Wait (Now + TimeValue("0:00:03"))
i = 2 'For i = 2 To 3
With ws
a = 1267
d = 1261
b = "15 - May - 19"
c = "25 - May - 19"
End With
For Each g In appIE.document.getElementsByClassName("return-location")
If g.className = "return-location" Then
g.Click
Exit For
End If
Next g
Do While appIE.Busy And e Is Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:02"))
Loop
Application.Wait (Now + TimeValue("0:00:02"))
' finds the pickup branch in html and clicks selection
Set e = appIE.document.getElementById("pickup-depot")
For Each O In e.Options
If O.Value = a Then
O.Selected = True
Exit For
End If
Next
Do While appIE.Busy And e Is Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:03"))
Loop
Application.Wait (Now + TimeValue("0:00:02"))
'sets the return branch and clicks the selection
Set e = appIE.document.getElementById("return-depot")
For Each O In e.Options
If O.Value = d Then
O.Selected = True
Exit For
End If
Next
Do While appIE.Busy And f Is Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:03"))
Loop
Do While appIE.Busy And l Is Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Loop
Application.Wait (Now + TimeValue("0:00:01"))
'Clicking find a vehicle
For Each l In appIE.document.getElementsByTagName("input")
If l.className = "btn" Then
l.Click
Exit For
End If
Next
Application.Wait (Now + TimeValue("0:00:04"))
' On Error Resume Next
Do While appIE.Busy
Application.Wait (Now + TimeValue("0:00:04"))
DoEvents
Loop
'While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend
Set carclick = appIE.document.querySelectorAll(".select-vehicle")
For x = 1 To carclick.Length
carclick.Item(x).Click
'While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend
Application.Wait (Now + TimeValue("0:00:02"))
' On Error Resume Next
Do While appIE.Busy
Application.Wait (Now + TimeValue("0:00:02"))
DoEvents
Loop
'This is where I tried to scrape the One-Way Fee value of 1315.79
'ws.Cells(2, 3).Value = appIE.document.querySelector(".sidebar__list- item:nth-of-type(13) span:nth-of-type(1)").innerText
Application.Wait (Now + TimeValue("0:00:02"))
' On Error Resume Next
Do While appIE.Busy
Application.Wait (Now + TimeValue("0:00:02"))
DoEvents
Loop
Set backbutton = appIE.document.querySelectorAll(".back.btn")
backbutton.Click
While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend
Exit For
Next x
End With
End Sub