question

AlexCorovin-0880 avatar image
1 Vote"
AlexCorovin-0880 asked IanXue-MSFT answered

Login to URL page use powershell script

Hi Everyone,

Could you please help me to login to the page I use this script below, the script only works before opening the site and added credentials but can not click see below error

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible

$username="username"

$password="password"

$ie.Navigate("https://domain.com/login")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 10;}

$usernamefield = $ie.document.getElementByID('lemail')
$usernamefield.value = "$username"

$passwordfield = $ie.document.getElementByID('password')
$passwordfield.value = "$password"

$Link = $ie.document.getElementByID('login')
$Link=$ie.Document.getElementsByTagName("button") | where-object {$_.type -eq "Log In"}
$Link.click()
error

You cannot call a method on a null-valued expression.
At line:20 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull


see below Inspect Button Log in


56704-2021-01-14-11-24-59-login.png




thank you very much for your help,


windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
1 Vote"
IanXue-MSFT answered IanXue-MSFT edited

Hi,

In your source file, "Log In" is not the type of the button but the text of the span. See if this works for you.

 $link = $ie.document.documentElement.getElementsByTagName('span') | where-Object {$_.textContent -eq 'Log In' }
 $link.click()

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexCorovin-0880 avatar image
0 Votes"
AlexCorovin-0880 answered

thank you for you help, could you help me please how i can click save by powershell script in IE

57098-2021-01-15-15-53-57-login-to-url.png


thank you



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

IanXue-MSFT avatar image
1 Vote"
IanXue-MSFT answered

Hi,

Try simulating keyboard input SendKeys

 do {
     Start-Sleep -Seconds 1
 }
 while ($ie.busy)
 [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
 [Microsoft.VisualBasic.Interaction]::AppActivate("Internet Explorer")
 [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
 [System.Windows.Forms.SendKeys]::Sendwait("{RIGHT}{RIGHT}{ENTER}")

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.