<Python, PyAutoGui, Selenium> 認証ウインドを乗り越える、、

ブラウザBrowserが出す認証ウインドAuthentication Requiredを通過する技。
ググるとこのウインドは、ブラウザが出すもので、Seleniumで制御できないっぽい。

ということで、PyAutoGuiで対応したっす。

ブラウザを画面いっぱいにして、
真ん中に現れる認証ウインドをクリック、
そして、タブで入力箇所を移動して、
IDとパスを入れる。
その後は、Seleniumに制御を戻す。

from selenium import webdriver
import pyautogui as pa

d = webdriver.Firefox()
d.maximize_window()

url = 'hoge.hoge.com'

w, h = pa.size()
pa.moveTo(x=w / 2, y=h / 2, duration=0.0)

#Open Browser 
d.get('')
time.sleep(2)

#Click Browser and Select URL entry
pa.click(x=w / 2, y=h / 2, clicks=2, button="left")
pa.press(keys="tab", presses=2)

#Input URL and Return "Enter" key
pa.typewrite(url, interval=0.0)
pa.press(keys="enter", presses=1)
time.sleep(2)

#Select Authentication Required popup window and enter user_id/password
pa.click(x=w / 2, y=h / 2, clicks=2, button="left")
pa.press(keys="tab", presses=4)
pa.typewrite('USER', interval=0.0)
pa.press(keys="tab", presses=1)
pa.typewrite('PASSWORD', interval=0.0)
pa.press(keys="enter", presses=1)
time.sleep(5)

#Get Target Page object by Selenium
url = 'http://hoge.hoge.com/hage/hagex/'
d.get(url)

ぼちぼち動いた。