トップページ > Selenium API(逆引き) > 【Java】getPosition

【Java】getPosition・・・ウィンドウの位置を取得する

【PR】業界トップクラスの「高単価報酬」「低マージン」を実現!レバテックフリーランス

「get_window_position」はカレントウインドウ(ブラウザ)の座標位置を取得します。取得する座標位置はウインドウ左上隅になります。

説明

◆メソッド
  ・Point getPosition()
◆使用形態
  ・driver.manage().window().getPosition()
◆備考
  ・特になし
◆関連項目
  ・ウィンドウのサイズを取得する
  ・全てのクッキーを取得する

サンプル

import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class WebTest{
  public static void main(String[] args){
    //Chrome制御のためChromeDriverのパスを指定
	System.setProperty("webdriver.chrome.driver",
		                            "D:\\AutoTest\\chromedriver.exe");
	//Chromeを起動する
	WebDriver driver = new ChromeDriver();
    //指定したURLに遷移する
    driver.get("https://www.google.co.jp");
    //カレントウィンドウの座標(左上隅の座標)を取得
    Point culPosition = driver.manage().window().getPosition();
    //カレントウィンドウの座標をコンソール出力
    System.out.println("ウィンドウの座標は" + culPosition);
  }
}
※selenium version 4.1.4で動作確認をしています(ブラウザのUIや属性値などが変更された場合、実行結果が異なる可能性があります)

実行結果

ウィンドウの座標は(10, 10)
getPosition
 ※GoogleおよびGoogleロゴはGoogle Inc.の登録商標であり、同社の許可を得て使用しています。

動画デモ

※字幕をONにすると解説のテロップが表示されます※


Warning: Invalid argument supplied for foreach() in /home/users/1/monda-muki/web/seleniumqref.com/api/java/window_get/Java_getPosition.html on line 167

JavaAPIアクセス TOP10
過去1週間(4/11~4/17)

    カテゴリー

    環境構築

    APIリファレンス

    その他

    ページ上部へ戻る
    トップページ > Selenium API(逆引き) > 【Java】getPosition
    Copyright © 2016- Seleniumクイックリファレンス All Rights Reserved