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.1をインストールしてみました。

    下記の記事にもあるように、開発者向けにWindows 8.1の製品版(…

  2. Windows 10

    Windows 10 November 2019 UpdateをISO形式でダウンロードして実機にイ…

    下記記事にもあるように、11月12日(米国時間)にWindows 10…

  3. Windows 10

    Microsoft Edgeのお気に入りをHTML形式でインポート・エクスポートする。

    以前当ブログでMicrosoft Edgeのお気に入りを編集する方法に…

  4. Windows 10

    「ファイル名を指定して実行」からMicrosoft Edgeを起動する

    以前書いた記事で、Microsoft EdgeをVBScriptから起…

  5. Windows 10

    【2017年4月版】Microsoft Edgeで開いているページを名前を付けて保存する方法

    2015年8月に、Microsoft Edgeで開いているページを名前…

コメント

  • コメント (0)

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP