「position」はウインドウ(ブラウザ)の座標位置を取得します。取得する座標位置はウインドウ左上隅になります。
説明
◆メソッド ・position ◆使用形態 ・driver.manage.window.position ◆備考 ・特になし ◆関連項目 ・スクリーンショット(ファイル)を取得する ・ウィンドウのサイズを取得する
サンプル
require 'selenium-webdriver' # Firefoxを起動 driver = Selenium::WebDriver.for(:firefox) # Googleページに移行 driver.get('https://www.google.co.jp/') #カレントウィンドウの座標(左上隅の座標)を取得 coordinate = driver.manage.window.position #取得した座標を表示 print(coordinate)
※selenium version 4.1.0で動作確認をしています
実行結果
#<struct Selenium::WebDriver::Point x=4, y=4>
動画デモ
※字幕をONにすると解説のテロップが表示されます※