1

Courtesy of this post, the following code auto-logs into a URL using MS IE and works great. The first two lines are the most important here. See below for what happens when I change them. I want to make it clear That I am not a professional web developer. I am only a system administrator forced to hack my way along when it comes to coding.

Working code when PowerShell calls IE:

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
$username="myname"
$RSAPIN="mypin"
$password="mypassword"
$ie.Navigate("https://www.tibia.com/mmorpg/free-multiplayer-online-role-playing-game.php")

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

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

$RSAPINfield = $ie.document.getElementByID('password_input')
$RSAPINfield.value = "$RSAPIN"

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

Non-working code is shown below; If I change the code to call MS Edge instead, I get a raft of errors and I think it's because PowerShell New-Object doesn't support MS Edge?

$msedge = New-Object -ComObject 'internetExplorer.Application'
$msedge.Visible= $true # Make it visible
$username="myname"
$RSAPIN="mypin"
$password="mypassword"
$msedge.Navigate("https://www.tibia.com/mmorpg/free-multiplayer-online-role-playing-game.php")

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

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

$RSAPINfield = $msedge.document.getElementByID('password_input')
$RSAPINfield.value = "$RSAPIN"

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

Errors seen when calling MS Edge instead of IE:

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). At C:\Scripts\msedge.ps1:3 char:11

  • $msedge = New-Object -ComObject 'msedge.Application'
  •       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
      The property 'Visible' cannot be found on this object. Verify that the property exists and can be set. At C:\Scripts\msedge.ps1:4 char:1
  • $msedge.Visible= $true # Make it visible
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound   You cannot call a method on a null-valued expression. At
    

C:\Scripts\msedge.ps1:8 char:1

  • $msedge.Navigate("myurl")
  •   + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull   You cannot call a method on a null-valued expression. At
    

C:\Scripts\msedge.ps1:12 char:1

  • $usernamefield = $msedge.document.getElementByID('username')

I am at a loss here. According to this post, PowerShell New-Object only supports IE's COM Automation.

4
  • Does this answer your question? Will Microsoft Edge support COM automation (InternetExplorer object)? Commented Sep 5, 2021 at 15:51
  • That's the link I provided in the bottom of my post. My question to the community is, does anyone have any code examples of how to do what I was doing with IE, but with Edge? Commented Sep 5, 2021 at 16:01
  • I haven't tried personally but maybe WebDriver learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/… Commented Sep 5, 2021 at 16:52
  • Hi @JohnRSmith May I know if you have got any chance to check my answer? Is it helpful to deal with the issue? I am glad to help if you have any other questions. Commented Sep 9, 2021 at 1:44

1 Answer 1

1

You can't automate the Edge Chromium browser like what you do with IE using PowerShell script. The COM automation interface are for IE, so it doesn't work with Edge. Besides, Edge doesn't have such interface.

It's recommended to use Selenium WebDriver to automate Edge. Selenium web driver supports many developing languages, you can choose the desired language.

You can also refer to the official doc of Selenium to learn how to get start with Selenium and refer to the code sample of different languages.

Sign up to request clarification or add additional context in comments.

Comments

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.