Unable to find element after clicking submit button in VBA using Selenium

silverfang

New Member
Joined
Mar 19, 2020
Messages
11
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
I have an issue with the loading of web page after the whole form is filled neatly. The next page is where i need to do data extraction. This is the website: https://enquiry.icegate.gov.in/enquiryatices/sbTrack

Please find sample data here :

SELECT LOCATION : HYDERABAD ICD (INSNF6)

ENTER SHIPPING BILL No. : 8991212

ENTER SHIPPING BILL DATE : 29-09-2017

ENTER IMAGE LETTERS : This is the Captcha( to be entered manually)
The issue is as soon as the submit button is clicked, the next page doesn't load and thus below lines are trying to find an element which didn't load at all. My friend have tried it with java and it seems to work with (.Refresh) but in VBA , that's a problem.

Please someone help me out here.

VBA Code:
Option Explicit
Sub icegateNewww()
Dim e, bot As WebDriver, ele As SelectElement, eledpTD As Object, r As Long, i As Long
Dim elem  As WebElement
Set bot = New WebDriver
r = 1

With bot
.Start "Chrome"
While (Len(Range("A" & r)) > 0)

          .Get "https://enquiry.icegate.gov.in/enquiryatices/sbTrack"
'line:
        .FindElementByXPath("//select[@id='location']").SendKeys Range("A" & r)
        .FindElementByXPath("//input[@id='sbNO']").SendKeys Range("B" & r)
        .FindElementByXPath("//img[@src='/enquiryatices/image/Dateicon.gif']").Click            'To open date picker
                    
        'To pick up the date
        
        Set ele = .FindElementByName("calendar-month").AsSelect
        ele.SelectByIndex Month(Cells(r, 3)) - 1
        Set ele = .FindElementByName("calendar-year").AsSelect
        ele.SelectByValue CStr(Year(Cells(r, 3)))
        Set eledpTD = .FindElementsByClass("dpTD")
        For Each e In eledpTD
            If Val(e.Text) = Val(Day(Cells(r, 3))) Then
                e.Click: Exit For
            End If
        Next e
              
      .FindElementById("captchaResp").Click
      .Wait 10000
      .FindElementByXPath("//input[@id='SubB']").Click               'To click on the submit button
    
'If (.FindElementByXPath("//span[contains(text(),'Invalid Code! Please try again!')]") = "Invalid Code! Please try again!") Then
'End If
  
'GoTo line

       .Wait (3000)
        
                                
      'Below lines are to click on each element & extract the data
      
      .FindElementByXPath("//span[contains(text(),'SB Details')]").Click
      Range("D" & r) = .FindElementByXPath("//div[@id='sbICES_Details']//center//div//table").Text
      
      
      .FindElementByXPath("//span[contains(text(),'Item Wise Reward Details')]").Click
      Range("E" & r) = .FindElementByXPath("//div[@id='itemWiseRewardTdId']//center//div//table").Text
      
r = r + 1
Wend
End With
End Sub


Also, there's an issue with Captcha, if by mistake it is typed wrong, then the whole problem falls apart, and doesn't take in next values from excel file.

Can this be resolved via "On error resume next"
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top