Windows 10

[Selenium]ExecuteScriptで指定した要素のIDを取得する。

MSDN フォーラムにあった質問「Edge向けWebDriverでDOMElementを取得するスクリプトを動かすと正しいJSONが戻らない」で、ExecuteScriptの戻り値でelement idが取得できることを知ったので、忘れないうちにメモしておきます。

using System;
using System.Collections.Generic;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;

namespace EdgeSample
{
  class Program
  {
    public static void Main(string[] args)
    {
      const string folderName = "Microsoft Web Driver";
      string serverPath = System.IO.Path.Combine(
        System.Environment.GetFolderPath(
          System.Environment.SpecialFolder.ProgramFilesX86
        ), folderName
      );
      EdgeDriver driver = new EdgeDriver(serverPath);
      driver.Navigate().GoToUrl("http://bing.com/");
      WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
      wait.Until(x => x.Title.Contains("Bing"));
      Dictionary<string, object> result = (Dictionary<string, object>)driver.ExecuteScript("return document.getElementById('sb_form_q');");
      Console.WriteLine(result["id"]);
      RemoteWebElement elm = (RemoteWebElement)driver.FindElementById("sb_form_q");
      elm.SendKeys("Test"); //element idが上記'result["id"]'と一致
      Console.ReadKey(true);
    }
  }
}

[Word VBA]ルビ(ふりがな)ダイアログの操作に挑む(2)前のページ

2015年10月の人気記事次のページ

関連記事

  1. Windows関連

    Windows 8にClassic Shellをインストールしてみました。

    ※ 下記はWindows 8 RTM(日本語版・64ビット)に基づいて…

  2. Windows関連

    Windows 10 IMEの「クラウド候補機能」の仕組みを追ってみた。

    「ついにWindows 10 日本語IMEにクラウド候補機能が搭載され…

  3. Windows 10

    [Windows 10]Microsoft Edgeに検索プロバイダーを追加する方法

    Windows 10のEdgeでは、デフォルトの検索エンジン(検索プロ…

  4. Windows 10

    [Windows 10]Creators UpdateのISOファイルを直接ダウンロードする方法

    下記記事の通り、本日(2017/4/5(米国時間))から「Window…

  5. Windows 10

    Chromium版のEdgeの小ネタ

    前回の記事で書いた通り、Chromium版のEdgeのプレビュー版が公…

  6. Windows 10

    Windows 10に昔のソフトを入れてみました。

    「Windows 10 Technical PreviewにOffic…

コメント

  • コメント (0)

  • トラックバックは利用できません。

  1. この記事へのコメントはありません。

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP