Share via


Powershell and Internet Explorer automation.

Question

Thursday, January 7, 2016 8:45 PM

Hi,

I tried to create a automatic login to a certain website. It has a field for the userid and a field for the password and a button to logon. The part to click on the button to logon I can seem to get this done. When press F12 on the site and click on the button I get this code:

<a tabIndex="3" class=" sw-btn-primary sw-btn" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$BodyContent$ctl05", "", true, "", "", false, true))" automation="Login">

I don't know what I shoud right to click on the button automaticly, This is my code so far:

 

 $url= "http://orion/"
 $username="xxxxxx" 
 $password="xxxxxx"  


 $ie = New-Object -com internetexplorer.application; 
 $ie.visible = $true; 
 $ie.navigate($url);


 while ($ie.Busy -eq $true) 
 { 
     Start-Sleep -Milliseconds 1000; 
 } 
 $ie.Document.getElementById("ctl00_BodyContent_Username").value = $username 
 $ie.Document.getElementByID("ctl00_BodyContent_Password").value = $password Who can help me? Greetings Peter Kiers

All replies (4)

Thursday, January 7, 2016 10:02 PM âś…Answered

Hello PeetK,

you can use the getElementByClassName Method from Document.documentElement. The examples uses the Sign In Link on technet.microsoft.com which is identified by classname too.

$url = 'https://technet.microsoft.com'
$ie = New-Object -ComObject internetexplorer.application
$ie.Visible = $true
$ie.Navigate($url)

while ($ie.Busy -eq $true) 
 { 
     Start-Sleep -Milliseconds 1000; 
 } 

$($ie.Document.documentElement.getElementsByClassName('scarabLink')).click()

Regards, Olaf


Saturday, January 9, 2016 6:19 PM

I have test ik but it does not work.


Saturday, January 9, 2016 6:48 PM

Oooh now it works. Thanks. Peter


Monday, April 4, 2016 12:10 PM

Hi

Is it possible that you would share the code that you are using?

I am trying to automate an weblogin, for a webpage:

onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl03$butLogin", "", true, "", "", false, false))" id="ctl03_butLogin" class="action" data-inline="true" data-theme="a">

But i cannot figure out how to post, the right way..

Knows that this is at bit thin, but is quite new to automating web :/

Thanks on advance :-)

/Graves