2017-01-09 26 views
3

PowerShellを使用してWebサイトにログインしようとしています。以下の例では、live.comにログインしようとしています。PowerShellのIEオートメーションを使用して入力の検証を行っているWebサイトにログインする

私はユーザー名フィールドを更新できますが、Webページは自分の値を受け入れない入力検証を実行します。私が手動で入力してスペースを叩くようにユーザー名フィールドを編集してから、バックスペースを入力すると、その入力は有効です。

フォーカスを変更したり、fireeventを使用したりすることについてのドキュメントがありますが、どちらも動作していないようです。

sendkeysは私の問題を解決しますが、以前はsendkeysに数多くの問題がありましたが、実際にはそのパスを避けたいと思っています。

$Site = 'https://login.live.com' 
$UserName = '[email protected]' 

$ie = New-Object -ComObject 'internetExplorer.Application' 
$ie.Visible= $true 
$ie.Navigate($Site) 
while ($IE.busy) 
{ 
    Start-Sleep -Milliseconds 100 
} 
$Inputs = $IE.document.getElementsByTagName("input") 
foreach ($Input in $Inputs) 
{ 
    if ($Input.type -eq "email") 
    { 
     $UserIDField = $Input   
    } 
    if ($Input.type -eq "submit") 
    { 
     $LoginButton = $Input   
    }   
} 

$UserIDField.focus() 
$UserIDField.value = $UserName 
$UserIDField.FireEvent('onchange') 
$LoginButton.focus() 
$LoginButton.click() 
+0

優れたユーザー認証システムは、自動ログインを防止するように設計されています。ユーザーはログインプロンプトで「ログインしたままにする」オプションを選択して、サイト訪問の間認証を維持することができます。自動化の必要はありません。 –

答えて

0

ウェブサイトで自動ログインが確認されている場合、この方法でどのように自動化されることが期待できますか? Sendkeysは、実際にユーザーの入力と同様のものを実際に送信し、その場合、ユーザーの問題をソートします。

Iは、Webサービスのための利用可能なAPIはログインして取得するがあるかどうかを確認したいと思います。それ以外

を、私はあなたを助けることができる何も表示されません。この懸念は、PowerShellやスクリプト言語に関するものではありません。あなたのウェブサイトにはかなり一般的です。

2

@Ranadip Duttaはそうだとは限りませんが、Webブラウザを自動化したい場合は、Seleniumが良いツールです。ここでは、WebサイトでChromeを自動化するのに5分かかります。 IEドライバ、Mozilla、Operaを選ぶことができます。そのためにはSeleniumをご覧ください。

# Selenium directory is the place where I expand Selenium Client & WebDriver Language Bindings for C# 
$seleniumDir = 'D:\Developpements\Pgdvlp_PowerShell\selenium-dotnet-3.0.0' 

# Selenium Webdriver 
Add-Type -Path "$seleniumDir\net40\WebDriver.dll" 
Add-Type -Path "$seleniumDir\net40\WebDriver.Support.dll" 
Add-Type -Path "$seleniumDir\net40\ThoughtWorks.Selenium.Core.dll" 
Add-Type -Path "$seleniumDir\net40\Selenium.WebDriverBackedSelenium.dll" 

# With Chrome 
# I Download Chrome driver here : https://chromedriver.storage.googleapis.com/index.html?path=2.25/ 
# It stands in "$seleniumDir" drive 
$chrome = New-Object OpenQA.Selenium.Chrome.ChromeDriver "$seleniumDir" 
#$chrome.Navigate().GoToUrl("https://fr.hightail.com/loginSpaces?redirect_url=https%3A%2F%2Fspaces.hightail.com%2Foauth%2Fhightail"); 
$chrome.Navigate().GoToUrl("https://login.live.com"); 
$Browser = $chrome 

$email = $Browser.FindElements([OpenQA.Selenium.By]::Name('loginfmt')) 
$email[0].SendKeys("[email protected]") 
$button = $Browser.FindElements([OpenQA.Selenium.By]::Id('idSIButton9')) 
$button.Click() 
Start-Sleep 2 
$passwd = $Browser.FindElements([OpenQA.Selenium.By]::Name('passwd')) 
$passwd[0].SendKeys("toto") 
$button = $Browser.FindElements([OpenQA.Selenium.By]::Id('idSIButton9')) 
$button.Click() 
関連する問題