1

I'm finding it difficulty in extracting the ( changing) XPath text in the final result page. This website : http://dgftcom.nic.in/licasp/IecDenQuery.asp Few IEC sample Codes are

  1. 0504057006 ---> This yields result such as FIRM name
  2. 0504057007 ---> This yields Invalid IEC code message
  3. 0504057006
  4. 0504057007
  5. 0504057006

    Option Explicit
    
    Public Sub EntityList()
    
    Dim bot As WebDriver
    Dim count As Long
    
    Set bot = New WebDriver
    bot.Start "Chrome"
    count = 1
    While (Len(Range("A" & count)) > 0)
    
    bot.Get "http://dgftcom.nic.in/licasp/IecDenQuery.asp"
    bot.FindElementByXPath("//input[@type='text'][@name='IEC']").SendKeys Range("A" & count)
    bot.FindElementByXPath("//input[@type='submit'][@name='B1']").Click
    
    Range("B" & count) = bot.FindElementByXPath("/html/body/table[2]/tbody/tr/td/font/strong").Text
    'Range("B" & count) = bot.FindElementByXPath("//table/tbody/tr[1]/td[1]").Text
    
    bot.Wait 1000
    
    count = count + 1
    Wend
    bot.Quit
    End Sub
    

The issue here is, when the next IEC code is entered, there is a change in the XPath, and this is where the whole code ends abruptly.

2 Answers 2

1

Try this following XPath.

//font[contains(.,'IEC :')]

Code:

Range("B" & count) = bot.FindElementByXPath("//font[contains(.,'IEC :')]").Text
Sign up to request clarification or add additional context in comments.

2 Comments

Sir, that's Genius ! Could you please explain me briefly ? I was thinking of trying "if" and "OR" techniques.
@AmitShah : Checking the string IEC : contains inside font tag which is fixed for valid or invalid code on the webpage.
1

There are one of two combinations based on whether results table has results. You can use css Or syntax. Should be faster than xpath

Range("B" & count) = bot.FindElementByCss("table td, table + font").Text

2 Comments

Thanks a lot sir for your support from the beginning and going forward , i have seen a steady growth in my coding skills , but whenever i come to Stack Overflow i feel ashamed of asking questions. It is guys like you who give encourage such coders to strive for more. I didn't know much around CSS , after your answer i have been into it since 4-5 hours.
No need to feel ashamed for asking questions provided you do attempt research and share your efforts. You can learn more about css here: developer.mozilla.org/en-US/docs/Web/CSS/Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.