Página 1 de 1

Ajuda com Conexão web

Enviado: Seg Dez 10, 2018 2:25 pm
por jose7br
Boa tarde pessoal, todos bem?

Estou fazendo um código para logar em um site da intranet daqui onde trabalho. Mas está dando uns erros

Alguém para dar uma ajuda?

Segue um scprit que peguei da pagina com os valores dos camppos e segue o codigo de login


Sub Login()

Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = ""
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True

Do
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.Document
HTMLDoc.all.Ecom_User_ID.Value = ""
HTMLDoc.all.Ecom_Password.Value = ""

For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "IDPLogin" Then oHTML_Element.Click: Exit For

Next
Err_Clear:

Resume Next
End Sub



'---------------------------------------------------------------------------------------------------
script da intranet

<script>
function safeSetGlobalMessage(strMessage)
{
var proofOfEndUserEnvironment= document.getElementById('runningInEndUserLoginEnvironment');
if (proofOfEndUserEnvironment)
{
setGlobalMessage(strMessage);
}
}

function submitForm()
{
var userNameEditBox = document.getElementById('Ecom_User_ID');
var passwordEditBox = document.getElementById('Ecom_Password');
if ((null != userNameEditBox) && (null != passwordEditBox))
{
if ((0 == userNameEditBox.value.length) || (0 == passwordEditBox.value.length))
{
safeSetGlobalMessage("Digite os valores para o nome de usuário e senha.");
userNameEditBox.focus();
return;
}

//if recaptcha is enabled just let the recaptcha code submit the document after verification


// Get some values from elements on the page:
var form = document.getElementById('IDPLogin');
var url = form.action;

safeSetGlobalMessage("Validando Credenciais...");

var proofOfEndUserEnvironment= document.getElementById('runningInEndUserLoginEnvironment');
if (proofOfEndUserEnvironment)
{
url = updateQueryString("uiDestination", "contentDiv", url);

// Send the data using post
var posting = $.post( url, $("#IDPLogin" ).serialize());

// Put the results in a div
posting.done(function( data )
{
safeSetGlobalMessage("");
$('#theNidpContent').html(data);
});

posting.fail(function()
{
safeSetGlobalMessage("Erro ao se comunicar com o servidor de identidade");
});
}
else
{
document.IDPLogin.submit();
}
}
}


function submitForm2() {
// Get some values from elements on the page:
var form = document.getElementById('IDPLogin');
var url = form.action;

safeSetGlobalMessage("Validando Credenciais...");

var proofOfEndUserEnvironment= document.getElementById('runningInEndUserLoginEnvironment');
if (proofOfEndUserEnvironment)
{
url = updateQueryString("uiDestination", "contentDiv", url);

// Send the data using post
var posting = $.post( url, $("#IDPLogin" ).serialize());

// Put the results in a div
posting.done(function( data )
{
safeSetGlobalMessage("");
$('#theNidpContent').html(data);
});

posting.fail(function()
{
safeSetGlobalMessage("Erro ao se comunicar com o servidor de identidade");
});
}
else
{
document.IDPLogin.submit();
}
}

function onLoadFocus()
{
if (document.IDPLogin.Ecom_User_ID.value)
{
document.IDPLogin.Ecom_Password.focus();
}
else
{
document.IDPLogin.Ecom_User_ID.focus();
}
}

$(document).ready(function(){

onLoadFocus();

$( "#loginButton2" ).click(function()
{
submitForm();
});

$( "#loginButton2" ).keyup(function(event)
{
if (isEnterKey(event) || isSpaceKey(event))
{
submitForm();
}
});

$("#Ecom_User_ID").keyup(function(event)
{
if (isEnterKey(event))
{
if (document.IDPLogin.Ecom_User_ID.value)
{
$("#loginButton2").click();
return false;
}
}
return true;
});

$("#Ecom_Password").keyup(function(event)
{
if (isEnterKey(event))
{
if (document.IDPLogin.Ecom_User_ID.value)
{
$("#loginButton2").click();
return false;
}
}
return true;
});
});

</script>

jose7br
Membro
Membro

Mensagens: 68
Registrado em: Seg Jan 09, 2017 1:11 pm
Agradeceu : 3 vezes
Foi agradecido: 0 time

Voltar ao topo

Re: Ajuda com Conexão web

Enviado: Qua Dez 19, 2018 12:32 am
por Mikel Silveira Fraga
José, boa noite e seja bem vindo ao fórum.

Bem cara, essa parte do script que você enviou, faz parte do JavaScript, que é responsável pela criação da interação entre Usuário e Sistema. Não tem nenhum informação relevante, para ser utilizada no processo de desenvolvimento da automação demandada.

Outra dica seria procurar os tópicos que falam sobre o tema aqui no fórum, pois é muito difícil para os membros do grupo te ajudarem com uma integração web, sendo que o sistema que necessita acessar esta em uma intranet, onde acaba sendo impossível a realização de testes e validação do código para lhe ajudar.

Comece entendendo a estrutura de HTML, que é a linguagem de construção dos elementos existentes em uma página. Através deste conhecimento, você já irá entender melhor como funciona essa parte do VBA e Web.

Caso tenha mais dúvidas, estamos a disposição para ajudar.

Abraços e excelentes estudos.