2011-08-11 165 views
6

私は、Webアプリケーション用の自動化テストを設定するためにSelenium Pythonバインディングを使用しています。イントラネットのユーザー名とパスワードにHTTP認証が必要なため、ベータ版サーバーでWebをテストする際に問題に直面しています。私はhttp://somewebsite.com/Selenium python-binding webdriverでHTTP認証を送信する方法

にアクセスする際に、ポップアップダイアログのユーザ名とパスワードを提出する必要があり

from selenium import webdriver 

driver = webdriver.Firefox() 
driver.get("https://somewebsite.com/") 

これを行うにはきちんとした方法はありますか?

答えて

7

が、私はこの質問への解決策を見つけた:

from selenium import webdriver 

profile = webdriver.FirefoxProfile() 
profile.set_preference('network.http.phishy-userpass-length', 255) 
driver = webdriver.Firefox(firefox_profile=profile) 
driver.get("https://username:[email protected]/") 

FirefoxProfileの一部は、デフォルトでは、Firefoxがpishingを防ぐために、ポップアップダイアログが表示されますので、確認ダイアログを閉じています。

+0

このソリューションは、あまりにも私のために働いたセレンのブラウザにクッキーをプッシュは(私は、Windows XP上のFirefoxの最後のバージョンを実行しますSP3、Pythonとセレンを使用)。 –

+0

解決策は私のために働いていません... – Alex

+1

これはもう機能しません – DelightedD0D

0

別の解決策:pythonの要求に

ログイン、クッキーを取得し、

 


    import requests 
    from selenium import webdriver 
    from requests.auth import HTTPBasicAuth 

    session = requests.Session() 
    www_request = session.get('http://example.com', auth=HTTPBasicAuth('username','password'), allow_redirects=False) 

    driver = webdriver.Remote(...) 
    #chrome needed to open the page before add the cookies 
    driver.get('http://example.com') 

    cookies = session.cookies.get_dict() 
    for key in cookies: 
     driver.add_cookie({'name': key, 'value': cookies[key]}) 

    driver.get('http://example.com') 

 
関連する問題