11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Selenium WebDriverでJavaScriptの変数を取得する

Last updated at Posted at 2014-04-18
    @Test
    public void test() throws Exception {
        driver.get(baseUrl + "/test/"); // 開く
        Wait<WebDriver> wait = new WebDriverWait(driver, 30);
        
        JavascriptExecutor js = (JavascriptExecutor) driver;
        String jsVar = (String) js.executeScript("return jsvariable;");
    }

実行するJavaScriptの中で取りたい変数をreturnすると取れます。

String jsVar = (String) js.executeScript( "return jsvariable;" );

古いバージョンで動作するかわかりません。
試したのはバージョン2.41.0です。

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?