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"
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,057
Hello


Were you able to solve this one?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,785
Messages
5,574,262
Members
412,581
Latest member
Rami100
Top