1
votes

I'm writing a PowerShell script that does a bunch of screen scraping off of an intranet website. I don't have access to, nor can I modify, the source code of the website.

The script starts out with opening Internet Explorer (IE11 is required due to company policies), then navigates through a couple of pages and performs actions based on information scraped from the individual pages. Everything appears to be working fine.

On one specific page, the script has to enter information in 2 input boxes to generate a list of hyperlinks and then select one of the hyperlinks, using click(). The hyperlink is a href to void(0) and then a JavaScript function in onclick.

<td align="left" class="wGNodeStyle">
  <a href="javascript:void(0)" class="workgroupStyle" onclick="openWgMgmtWindow(2)">

The JavaScript function opens a new window and submits some user information to this new window.

function openWgMgmtWindow(selIndex) {
  document.getElementsByName("workgroupSo.groupId")[0].value = eval('document.all.wgGroupId'+selIndex+'.innerHTML');        
  document.getElementsByName("workgroupSo.primaryGroupId")[0].value = eval('document.all.wgGroupPrimary'+selIndex+'.innerHTML');
  document.getElementsByName("actionString")[0].value = "Search";

  var w = window.open("", document.forms['formManageWG'].target,winProps);
  w.focus();
  document.forms['formManageWG'].submit();
  return false;
}

Here's the problem:

If I open Internet Explorer outside of PowerShell, either by clicking its icon or even running the executable directly, navigate to the page in question and click the hyperlink, a new window opens and shows the expected screen. Even if I open Internet Explorer as just described and execute the script, omitting the scripted launch of IE, and just find the IE object, everything will work fine and a new window will open as above.

# & "$env:programfiles\Internet Explorer\iexplore.exe" 'https://www.ehpas.com'
$objEhpas = New-Object -comObject Shell.Application
do {
  Start-Sleep -Milliseconds 500
  $ieEhpas = @($objEhpas.windows() | ? {$_.locationName -like '*EHPAS Home Page*' })[0]
} while ($ieEhpas -eq $null)

However, if I let the script launch Internet Explorer, when I get to clicking the hyperlink page, a new blank window will open, and then a new tab will also open next to the tab with the hyperlink page, containing what was supposed to be in the new window. I can't find the new tab in the processes, so I can't take control of it.

The question is, what is the difference between opening Internet Explorer directly, versus opening it programmatically? And how do I get the programmatic version to behave the same as the direct?

I apologize for the long post.

1

1 Answers

0
votes

I finally found an answer to my question. Apparently, it's a bug in Internet Explorer 11 and it will not be fixed.

https://connect.microsoft.com/IE/feedback/details/812072/ie-11-window-open-issue

The problem exists for me because I'm running PowerShell in admin mode. Running PowerShell as "myself" resolves the problem of how IE is opened, but introduces some other challenges. Those, however, I should be able to code my way out of.