The task is kind o simple, yet complicated.
I'm trying to: 1. get the captcha image from a specific internet page 2. load it into a Picture.box inside a form. 3. the user type the characters which are sent back to the respective input in that page.
The site is: http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/Cnpjreva_Solicitacao2.asp
The captcha image is downloaded from a static address, there is no unique id in the url or any "src" attribute inside its DOM element.
Having no problem at downloading the image and showing it in a form (even it being png).
The issue is that each time the link of the image is accessed it generates any random captcha, so when the code downloads it, it gets a different image than the one on the page, which characters do not match the ones expected.
I've made a manual test, to load in a alternate tab of the browser the direct link of the captcha, which obviously returned a different image from that on the page, but for my surprise, typing its character even it being different worked. So, if a new image is generated in the same enviroment (in this example Internet explorer), it will match the expecteded sequence in the input of the page. So i think a workaround would have to do with dealing with cookies or sort of, but idk how...
The direct link of the Captcha Image is: http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/captcha/gerarCaptcha.asp
The small piece of code which concerns to this is:
IMGurl = "http://www.receita.fazenda.gov.br/PessoaJuridica/CNPJ/cnpjreva/captcha/gerarCaptcha.asp" 'Direct link of the captcha image
filepath = ThisWorkbook.Path & "\" & "captcha.png"
fileR = URLDownloadToFile(0, IMGurl, filepath, 0, 0)'function to download the image file
Load FrmCaptcha 'form to show the image downloaded
FrmCaptcha.Show
docweb.getElementsByTagName("input")(2).Value = FrmCaptcha.TextBox1.Value 'send the characters typed in the form to the input at the page.
docweb.getElementsByTagName("input")(3).click 'clicks the button
Unload FrmCaptcha 'unloads the form
Hope someone can help!