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. Office関連

    【2017年1月版】Microsoft Edgeを操作するVBAマクロ(DOM編)(2)

    昨日の記事で、Microsoft Edgeを操作するVBAコードを改め…

  2. Windows関連

    [Windows 8]便利な”クイックアクセス(Win + X)”メニュー

    Windows 8の便利なショートカットキーの一つとして「Win + …

  3. Windows 10

    [Windows 10]「WebとWindowsを検索」を消す方法

    Windows 10を使ってみて真っ先に思ったことが、タスクバーに表示…

  4. VBScript

    Microsoft Edgeのバージョン情報をクリップボードにコピーするVBScript

    前回の記事に引き続き、自分の手間を減らすためのスクリプト、今回はMic…

  5. Windows 10

    起動中のMicrosoft EdgeからタイトルとURLを取得するVBAマクロ(UI Automat…

    当ブログでは、Microsoft Edgeを外部から操作するプログラム…

  6. Windows 10

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

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

コメント

  • コメント (0)

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP