Selenium Webdriver on PowerShell SendKey function send keys on current active window, not the Selenium invoked browser
<p>I'm writing a PowerShell script that runs the Selenium Webdriver. What I'm planning to do is open up a page, open x tabs more, return to the first tab, do something, go to the next tab, do something, and so on.</p>

<p>But when I use the SendKeys on the code to send Ctrl+T to open up a new tab, unless the Selenium invoked browser is active, it sends Ctrl+T to my active window, (e.g, Powershell ISE (What it does is it opens a new PowerShell tab)).</p>

<p>I hope you can help me with this, guys. </p>

<p>Here's the code:</p>

<pre><code>Add-Type -AssemblyName "System.Windows.Forms"

Set-Location "$PSScriptRoot\selenium-dotnet-2.53.0\net35"
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\selenium-dotnet-2.53.0\net35\Selenium.WebDriverBackedSelenium.dll")
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\selenium-dotnet-2.53.0\net35\ThoughtWorks.Selenium.Core.dll")
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\selenium-dotnet-2.53.0\net35\WebDriver.dll")
[System.Reflection.Assembly]::LoadFrom("$PSScriptRoot\selenium-dotnet-2.53.0\net35\WebDriver.Support.dll")

$servers = `
"http://facebook.com", `
"http://google.com"

$driver = New-Object "OpenQA.Selenium.FireFox.FirefoxDriver"
$driver.Manage().Window.Maximize();

$actions = New-Object OpenQA.Selenium.Interactions.Actions($driver)

for ($i = 0; $i -lt $($servers.Length); $i++){
    $driver.Navigate().GoToUrl($servers[$i])
    if ($i + 1 -ne $($servers.Length)) {
        $driver.FindElementByCssSelector("body").SendKeys($body,[System.Windows.Forms.SendKeys]::SendWait("^t")) | Out-Null
    }
}

foreach($server in $servers){
    $driver.FindElementByCssSelector("body").SendKeys($body,       [System.Windows.Forms.SendKeys]::SendWait("^{TAB}")) | Out-Null
    $driver.SwitchTo().DefaultContent()
}
</code></pre>