ドライバーセッション 
    
      セッションの開始と停止は、ブラウザーを開いたり閉じたりするためのものです。
セッションの作成 
新しいセッションの作成は、W3C コマンド New session  に対応しています。
セッションは、新しいDriverクラスオブジェクトを初期化することによって自動的に作成されます。
各言語では、次のいずれかのクラス (または同等のもの) の引数を使用してセッションを作成することができます。
ローカルドライバー 
ローカルドライバーを起動するための主な一意の引数には、ローカルコンピューターで必要なドライバーサービスを起動するための情報が含まれます。
Service オブジェクトはローカルドライバーにのみ適用され、ブラウザーのドライバーに関する情報を提供します。 
 
リモートドライバー 
リモートドライバーを起動するための主な一意の引数には、コードを実行する場所に関する情報を含みます。
詳細は、リモートドライバー をご覧ください。
セッションの終了 
セッションの終了に対するW3Cコマンドは、セッションの削除 です。
重要:  quit メソッドは close メソッドとは異なり、
セッションを終了するには常に quit を使用することをお勧めします。
 
 
  
  
  
  
  
  
  
    
    
	
    
    
	1 - ブラウザーオプション 
    これらのCapabilityはすべてのブラウザで共通です。
	Selenium 3 では、Capabilitiesは Desired Capabilities クラスを使用してセッションで定義していました。
Selenium 4 以降、ブラウザ オプション クラスを使用する必要があります。
リモート ドライバー セッションの場合、使用するブラウザーを決めるため、ブラウザーオプションインスタンスが必要です。
これらのオプションは、Capabilities  の w3c仕様で説明しています。
各ブラウザには、w3c仕様で定義しているものに加えて定義可能な カスタム オプション  があります。
browserName 
このCapabilityは、特定のセッションの browserName を設定するために使います。
指定されたブラウザがリモートエンドにインストールされていない場合、セッションの作成は失敗します。
browserVersion 
このCapabilityはオプションです。
これは、リモートエンドで使用可能なブラウザーバージョンを設定するために使います。
たとえば、Chromeバージョン80のみがインストールされているシステムでバージョン75を要求すると、セッションの作成は失敗します。
pageLoadStrategy 
3種類のページ読み込み戦略を利用できます。
ページ読み込み戦略は、次の表で説明しています。
戦略 
準備完了状態 
注釈 
 
 
normal 
complete 
デフォルトで使用され、すべてのリソースをダウンロードするのを待ちます 
 
eager 
interactive 
DOM アクセスの準備は整っていますが、画像などの他のリソースはまだロード中の可能性があります 
 
none 
Any 
WebDriver をまったくブロックしません 
 
 
ドキュメントの document.readyState 
プロパティは、現在のドキュメントの読み込み状態を示します。
URL 経由で新しいページに移動する場合、デフォルトでは、WebDriver は、ドキュメントの準備完了状態が完了するまで、
ナビゲーション メソッド (driver.navigate().get() など) の完了を保留します。
これは必ずしもページの読み込みが完了したことを意味するわけではありません。 
特に、Ready State が完了した後に JavaScript を使用してコンテンツを動的に読み込むシングル ページ アプリケーションのようなサイトの場合はそうです。
また、この動作は、要素のクリックまたはフォームの送信の結果であるナビゲーションには適用されないことに注意してください。
自動化にとって重要ではないアセット (画像、css、js など) をダウンロードした結果、ページの読み込みに時間がかかる場合は、
デフォルトのパラメーターである normal を eager または none に変更して、セッションの読み込みを高速化できます。
この値はセッション全体に適用されるため、 待機戦略 
が不安定さを最小限に抑えるのに十分であることを確認してください。
normal (デフォルト) 
WebDriver は load 
イベント検知するまで待機します。
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        import  org.openqa.selenium.PageLoadStrategy ; 
import  org.openqa.selenium.WebDriver ; 
import  org.openqa.selenium.chrome.ChromeOptions ; 
import  org.openqa.selenium.chrome.ChromeDriver ; 
 public  class  pageLoadStrategy  { 
  public  static  void  main ( String []  args )  { 
     ChromeOptions  chromeOptions  =  new  ChromeOptions (); 
     chromeOptions . setPageLoadStrategy ( PageLoadStrategy . NORMAL ); 
     WebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
     try  { 
       // Navigate to Url
         driver . get ( "https://google.com" ); 
    }  finally  { 
       driver . quit (); 
     } 
   } 
 }  
     
    
        from  selenium  import  webdriver 
from  selenium.webdriver.chrome.options  import  Options 
options  =  Options () 
options . page_load_strategy  =  'normal' 
driver  =  webdriver . Chrome ( options = options ) 
driver . get ( "http://www.google.com" ) 
driver . quit ()  
     
    
        using  OpenQA.Selenium ; 
using  OpenQA.Selenium.Chrome ; 
 namespace  pageLoadStrategy  { 
  class  pageLoadStrategy  { 
     public  static  void  Main ( string []  args )  { 
       var  chromeOptions  =  new  ChromeOptions (); 
       chromeOptions . PageLoadStrategy  =  PageLoadStrategy . Normal ; 
       IWebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
       try  { 
         driver . Navigate (). GoToUrl ( "https://example.com" ); 
       }  finally  { 
         driver . Quit (); 
       } 
     } 
   } 
 }  
     
    
        require  'selenium-webdriver' 
options  =  Selenium :: WebDriver :: Options . chrome 
options . page_load_strategy  =  :normal 
 driver  =  Selenium :: WebDriver . for  :chrome ,  options :  options 
driver . get ( 'https://www.google.com' )  
     
    
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      it ( 'Navigate using normal page loading strategy' ,  async  function  ()  { 
       let  driver  =  await  env 
         . builder () 
         . setChromeOptions ( options . setPageLoadStrategy ( 'normal' )) 
         . build (); 
 
       await  driver . get ( 'https://www.google.com' );   
  
     
    
        import  org.openqa.selenium.PageLoadStrategy 
import  org.openqa.selenium.chrome.ChromeDriver 
import  org.openqa.selenium.chrome.ChromeOptions 
 fun  main ()  { 
  val  chromeOptions  =  ChromeOptions () 
   chromeOptions . setPageLoadStrategy ( PageLoadStrategy . NORMAL ) 
   val  driver  =  ChromeDriver ( chromeOptions ) 
   try  { 
     driver . get ( "https://www.google.com" ) 
   } 
   finally  { 
     driver . quit () 
   } 
 }  
     
 
eager 
WebDriver は、DOMContentLoaded 
イベントを検知するまで待機します。
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        import  org.openqa.selenium.PageLoadStrategy ; 
import  org.openqa.selenium.WebDriver ; 
import  org.openqa.selenium.chrome.ChromeOptions ; 
import  org.openqa.selenium.chrome.ChromeDriver ; 
 public  class  pageLoadStrategy  { 
  public  static  void  main ( String []  args )  { 
     ChromeOptions  chromeOptions  =  new  ChromeOptions (); 
     chromeOptions . setPageLoadStrategy ( PageLoadStrategy . EAGER ); 
     WebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
     try  { 
       // Navigate to Url
         driver . get ( "https://google.com" ); 
    }  finally  { 
       driver . quit (); 
     } 
   } 
 }  
     
    
        from  selenium  import  webdriver 
from  selenium.webdriver.chrome.options  import  Options 
options  =  Options () 
options . page_load_strategy  =  'eager' 
driver  =  webdriver . Chrome ( options = options ) 
driver . get ( "http://www.google.com" ) 
driver . quit ()  
     
    
        using  OpenQA.Selenium ; 
using  OpenQA.Selenium.Chrome ; 
 namespace  pageLoadStrategy  { 
  class  pageLoadStrategy  { 
     public  static  void  Main ( string []  args )  { 
       var  chromeOptions  =  new  ChromeOptions (); 
       chromeOptions . PageLoadStrategy  =  PageLoadStrategy . Eager ; 
       IWebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
       try  { 
         driver . Navigate (). GoToUrl ( "https://example.com" ); 
       }  finally  { 
         driver . Quit (); 
       } 
     } 
   } 
 }  
     
    
        require  'selenium-webdriver' 
options  =  Selenium :: WebDriver :: Options . chrome 
options . page_load_strategy  =  :eager 
 driver  =  Selenium :: WebDriver . for  :chrome ,  options :  options 
driver . get ( 'https://www.google.com' )  
     
    
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      it ( 'Navigate using eager page loading strategy' ,  async  function  ()  { 
       let  driver  =  await  env 
         . builder () 
         . setChromeOptions ( options . setPageLoadStrategy ( 'eager' )) 
         . build (); 
 
       await  driver . get ( 'https://www.google.com' );   
  
     
    
        import  org.openqa.selenium.PageLoadStrategy 
import  org.openqa.selenium.chrome.ChromeDriver 
import  org.openqa.selenium.chrome.ChromeOptions 
 fun  main ()  { 
  val  chromeOptions  =  ChromeOptions () 
   chromeOptions . setPageLoadStrategy ( PageLoadStrategy . EAGER ) 
   val  driver  =  ChromeDriver ( chromeOptions ) 
   try  { 
     driver . get ( "https://www.google.com" ) 
   } 
   finally  { 
     driver . quit () 
   } 
 }  
     
 
none 
WebDriver は、最初のページがダウンロードされるまで待機します。
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        import  org.openqa.selenium.PageLoadStrategy ; 
import  org.openqa.selenium.WebDriver ; 
import  org.openqa.selenium.chrome.ChromeOptions ; 
import  org.openqa.selenium.chrome.ChromeDriver ; 
 public  class  pageLoadStrategy  { 
  public  static  void  main ( String []  args )  { 
     ChromeOptions  chromeOptions  =  new  ChromeOptions (); 
     chromeOptions . setPageLoadStrategy ( PageLoadStrategy . NONE ); 
     WebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
     try  { 
       // Navigate to Url
         driver . get ( "https://google.com" ); 
    }  finally  { 
       driver . quit (); 
     } 
   } 
 }  
     
    
        from  selenium  import  webdriver 
from  selenium.webdriver.chrome.options  import  Options 
options  =  Options () 
options . page_load_strategy  =  'none' 
driver  =  webdriver . Chrome ( options = options ) 
driver . get ( "http://www.google.com" ) 
driver . quit ()  
     
    
        using  OpenQA.Selenium ; 
using  OpenQA.Selenium.Chrome ; 
 namespace  pageLoadStrategy  { 
  class  pageLoadStrategy  { 
     public  static  void  Main ( string []  args )  { 
       var  chromeOptions  =  new  ChromeOptions (); 
       chromeOptions . PageLoadStrategy  =  PageLoadStrategy . None ; 
       IWebDriver  driver  =  new  ChromeDriver ( chromeOptions ); 
       try  { 
         driver . Navigate (). GoToUrl ( "https://example.com" ); 
       }  finally  { 
         driver . Quit (); 
       } 
     } 
   } 
 }  
     
    
        require  'selenium-webdriver' 
options  =  Selenium :: WebDriver :: Options . chrome 
options . page_load_strategy  =  :none 
 driver  =  Selenium :: WebDriver . for  :chrome ,  options :  options 
driver . get ( 'https://www.google.com' )  
     
    
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      it ( 'Navigate using none page loading strategy' ,  async  function  ()  { 
       let  driver  =  await  env 
         . builder () 
         . setChromeOptions ( options . setPageLoadStrategy ( 'none' )) 
         . build (); 
 
       await  driver . get ( 'https://www.google.com' );   
  
     
    
        import  org.openqa.selenium.PageLoadStrategy 
import  org.openqa.selenium.chrome.ChromeDriver 
import  org.openqa.selenium.chrome.ChromeOptions 
 fun  main ()  { 
  val  chromeOptions  =  ChromeOptions () 
   chromeOptions . setPageLoadStrategy ( PageLoadStrategy . NONE ) 
   val  driver  =  ChromeDriver ( chromeOptions ) 
   try  { 
     driver . get ( "https://www.google.com" ) 
   } 
   finally  { 
     driver . quit () 
   } 
 }  
     
 
これにより、リモートエンドのオペレーティングシステムが識別され、 platformName を取得するとOS名が返されます。
クラウドベースのプロバイダーでは、 platformName を設定すると、リモートエンドのOSが設定されます。
acceptInsecureCerts 
この機能は、セッション中のナビゲーション中に、期限切れ(または)無効な TLS証明書 が使用されているかどうかを確認します。
機能が false に設定されている場合、ナビゲーションでドメイン証明書の問題が発生すると、
insecure certificate error   が返されます。
true に設定すると、無効な証明書はブラウザーによって信頼されます。
すべての自己署名証明書は、デフォルトでこの機能によって信頼されます。
一度設定すると、 acceptInsecureCerts Capabilityはセッション全体に影響します。
timeouts 
WebDriverの セッション には特定の セッションタイムアウト 間隔が設定されており、
その間、ユーザーはスクリプトの実行またはブラウザーからの情報の取得の動作を制御できます。
各セッションタイムアウトは、以下で説明するように、異なる タイムアウト の組み合わせで構成されます。
Script Timeout: 
現在のブラウジングコンテキストで実行中のスクリプトをいつ中断するかを指定します。
新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 30,000  が課されます。
Page Load Timeout: 
現在のブラウジングコンテキストでWebページをロードする必要がある時間間隔を指定します。
新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 300,000  が課されます。
ページの読み込みが指定/デフォルトの時間枠を制限する場合、スクリプトは TimeoutException  によって停止されます。
Implicit Wait Timeout 
これは、要素を検索するときに暗黙的な要素の検索戦略を待つ時間を指定します。
新しいセッションがWebDriverによって作成されると、デフォルトのタイムアウト 0  が課されます。
unhandledPromptBehavior 
現在のセッションの ユーザープロンプトハンドラー の状態を指定します。
デフォルトでは、 dismiss and notify (却下して通知する) 状態  となります。
User Prompt Handler 
これは、リモートエンドでユーザープロンプトが表示されたときに実行する必要があるアクションを定義します。
これは、 unhandledPromptBehavior Capabilityによって定義され、次の状態があります。
dismiss (却下) 
accept (受入) 
dismiss and notify (却下して通知) 
accept and notify (受け入れて通知) 
ignore (無視) 
 
setWindowRect 
リモート エンドがすべての サイズ変更および再配置 
コマンド  をサポートするかどうかを示します。
strictFileInteractability 
この新しいcapabilityは、厳密な相互作用チェックを input type = file  要素に適用する必要があるかどうかを示します。
厳密な相互作用チェックはデフォルトでオフになっているため、隠しファイルのアップロードコントロールで Element Send Keys 
を使用する場合の動作が変更されます。
proxy 
プロキシサーバーは、クライアントとサーバー間の要求の仲介役として機能します。
簡単に言えば、トラフィックはプロキシサーバーを経由して、要求したアドレスに戻り、戻ってきます。
Seleniumを使用した自動化スクリプト用のプロキシサーバーは、
ネットワークトラフィックをキャプチャする 
ウェブサイトによって行われた模擬バックエンドを呼び出す 
複雑なネットワークトポロジーまたは厳格な企業の制限/ポリシーの下で、必要なWebサイトにアクセスします。 
 
企業環境でブラウザがURLへの接続に失敗した場合、環境にアクセスするにはプロキシが必要であることが原因であることが最も可能性が高いです。
Selenium WebDriverは設定をプロキシする方法を提供します。
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        import  org.openqa.selenium.Proxy ; 
import  org.openqa.selenium.WebDriver ; 
import  org.openqa.selenium.chrome.ChromeDriver ; 
import  org.openqa.selenium.chrome.ChromeOptions ; 
 public  class  ProxyTest  { 
  public  static  void  main ( String []  args )  { 
     Proxy  proxy  =  new  Proxy (); 
     proxy . setHttpProxy ( "<HOST:PORT>" ); 
     ChromeOptions  options  =  new  ChromeOptions (); 
     options . setCapability ( "proxy" ,  proxy ); 
     WebDriver  driver  =  new  ChromeDriver ( options ); 
     driver . get ( "https://www.google.com/" ); 
     driver . manage (). window (). maximize (); 
     driver . quit (); 
   } 
 }  
     
    
        from  selenium  import  webdriver 
 PROXY  =  "<HOST:PORT>" 
webdriver . DesiredCapabilities . FIREFOX [ 'proxy' ]  =  { 
"httpProxy" :  PROXY , 
"ftpProxy" :  PROXY , 
"sslProxy" :  PROXY , 
"proxyType" :  "MANUAL" , 
 } 
 with  webdriver . Firefox ()  as  driver : 
# Open URL 
    driver . get ( "https://selenium.dev" )   
     
    
        using  OpenQA.Selenium ; 
using  OpenQA.Selenium.Chrome ; 
 public  class  ProxyTest { 
public  static  void  Main ()  { 
ChromeOptions  options  =  new  ChromeOptions (); 
Proxy  proxy  =  new  Proxy (); 
proxy . Kind  =  ProxyKind . Manual ; 
proxy . IsAutoDetect  =  false ; 
proxy . SslProxy  =  "<HOST:PORT>" ; 
options . Proxy  =  proxy ; 
options . AddArgument ( "ignore-certificate-errors" ); 
IWebDriver  driver  =  new  ChromeDriver ( options ); 
driver . Navigate (). GoToUrl ( "https://www.selenium.dev/" ); 
} 
}  
     
    
        # this code was written with Selenium 4 
 proxy  =  Selenium :: WebDriver :: Proxy . new ( http :  '<HOST:PORT>' ) 
cap    =  Selenium :: WebDriver :: Remote :: Capabilities . chrome ( proxy :  proxy ) 
 driver  =  Selenium :: WebDriver . for ( :chrome ,  capabilities :  cap ) 
driver . get ( 'http://google.com' )  
     
    
        let  webdriver  =  require ( 'selenium-webdriver' ); 
let  chrome  =  require ( 'selenium-webdriver/chrome' ); 
let  proxy  =  require ( 'selenium-webdriver/proxy' ); 
let  opts  =  new  chrome . Options (); 
 ( async  function  example ()  { 
opts . setProxy ( proxy . manual ({ http :  '<HOST:PORT>' })); 
let  driver  =  new  webdriver . Builder () 
. forBrowser ( 'chrome' ) 
. setChromeOptions ( opts ) 
. build (); 
try  { 
await  driver . get ( "https://selenium.dev" ); 
} 
finally  { 
await  driver . quit (); 
} 
}());  
     
    
        import  org.openqa.selenium.Proxy 
import  org.openqa.selenium.WebDriver 
import  org.openqa.selenium.chrome.ChromeDriver 
import  org.openqa.selenium.chrome.ChromeOptions 
 class  proxyTest  { 
fun  main ()  { 
         val  proxy  =  Proxy () 
         proxy . setHttpProxy ( "<HOST:PORT>" ) 
         val  options  =  ChromeOptions () 
         options . setCapability ( "proxy" ,  proxy ) 
         val  driver :  WebDriver  =  ChromeDriver ( options ) 
         driver [ "https://www.google.com/" ] 
         driver . manage (). window (). maximize () 
         driver . quit () 
     } 
 }  
     
 
 
    
	
  
    
    
	
    
    
	2 - Command executors 
    
	These allow you to set various parameters for the HTTP library
 
    
	
  
    
    
	
    
    
	3 - Command Listeners 
    
	These allow you to execute custom actions in every time specific Selenium commands are sent
 
    
	
  
    
    
	
    
    
	4 - Driver Service Class 
    
	The Service classes are for managing the starting and stopping of drivers.
They can not be used with a Remote WebDriver session.
Service classes allow you to specify information about the driver,
like location and which port to use.
They also let you specify what arguments get passed
to the command line. Most of the useful arguments are related to logging.
Default Service instance 
To start a driver with a default service instance:
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
  from  selenium.webdriver.chrome.service  import  Service  as  ChromeService 
 
  
     
    
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      service  =  Selenium :: WebDriver :: Service . chrome 
     @driver  =  Selenium :: WebDriver . for  :chrome ,  service :  service   
  
     
    
    
 
Driver location 
Note:  If you are using Selenium 4.6 or greater, you shouldn’t need to set a driver location.
If you can not update Selenium or have an advanced use case here is how to specify the driver location:
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      driver  =  new  ChromeDriver ( service );   
  
     
    
    
        
Note: Unlike the other languages, the driver location should not include the file name, only the path to the directory the driver is in.
Selenium v4.9  
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
              driver  =  new  ChromeDriver ( service );   
  
     
    
        
Selenium v4.8  
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      service . executable_path  =  driver_path   
  
     
    
    
 
Driver port 
If you want the driver to run on a specific port, you may specify it as follows:
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        
  
  
  
  
  
  
  
  
    
    
    
    
    
    
  
      driver  =  new  ChromeDriver ( service );   
  
     
    
    
    
    
    
 
Logging 
Logging functionality varies between browsers. Most browsers allow you to
specify location and level of logs. Take a look at the respective browser page:
 
    
	
  
    
    
	
    
    
	5 - Remote WebDriver 
    
	WebDriverは、ローカルで使用するのと同じ方法でリモートで使用できます。
主な違いは、リモートWebDriverを設定して、別のマシンでテストを実行できるようにする必要があることです。
リモートWebDriverは、クライアントとサーバーの2つの部分で構成されています。
クライアントはWebDriverテストであり、サーバーは単純なJavaサーブレットで最新のJEEアプリサーバーでホストすることができます。
リモートWebDriverクライアントを実行するには、まずRemoteWebDriverに接続する必要があります。
これを行うには、テストを実行しているサーバーのアドレスをURLに指定します。
設定をカスタマイズするために、desired capabilitiesを設定します。
以下は、Firefoxでテストを実行しているリモートWebサーバー www.example.com   を指定してリモートWebDriverオブジェクトをインスタンス化する例です。
  
  
  
  
  
  
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        FirefoxOptions  firefoxOptions  =  new  FirefoxOptions (); 
WebDriver  driver  =  new  RemoteWebDriver ( new  URL ( "http://www.example.com" ),  firefoxOptions ); 
driver . get ( "http://www.google.com" ); 
driver . quit (); 
    
     
    
        from  selenium  import  webdriver 
 firefox_options  =  webdriver . FirefoxOptions () 
driver  =  webdriver . Remote ( 
    command_executor = 'http://www.example.com' , 
     options = firefox_options 
 ) 
driver . get ( "http://www.google.com" ) 
driver . quit ()  
    
     
    
         FirefoxOptions  firefoxOptions  =  new  FirefoxOptions (); 
  IWebDriver  driver  =  new  RemoteWebDriver ( new  Uri ( "http://www.example.com" ),  firefoxOptions ); 
  driver . Navigate (). GoToUrl ( "http://www.google.com" ); 
  driver . Quit (); 
     
     
    
        require  'selenium-webdriver' 
 driver  =  Selenium :: WebDriver . for  :remote ,  url :  "http://www.example.com" ,  desired_capabilities :  :firefox 
driver . get  "http://www.google.com" 
driver . close 
    
     
    
        const  {  Builder ,  Capabilities  }  =  require ( "selenium-webdriver" ); 
var  capabilities  =  Capabilities . firefox (); 
( async  function  helloSelenium ()  { 
    let  driver  =  new  Builder ()         
         . usingServer ( "http://example.com" )    
         . withCapabilities ( capabilities ) 
         . build (); 
     try  { 
         await  driver . get ( 'http://www.google.com' ); 
     }  finally  { 
         await  driver . quit (); 
     } 
 })();  
  
  
     
    
        firefoxOptions  =  FirefoxOptions () 
driver :  WebDriver  =  new  RemoteWebDriver ( new  URL ( "http://www.example.com" ),  firefoxOptions ) 
driver . get ( "http://www.google.com" ) 
driver . quit () 
    
     
 
テスト設定をさらにカスタマイズするために、他のdesired capabilitiesを追加できます。
ブラウザーオプション 
例えば、Chromeバージョン67を使用して、Windows XPでChromeを実行する場合は、このようになるかと思います。
  
  
  
  
  
  
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        ChromeOptions  chromeOptions  =  new  ChromeOptions (); 
chromeOptions . setCapability ( "browserVersion" ,  "67" ); 
chromeOptions . setCapability ( "platformName" ,  "Windows XP" ); 
WebDriver  driver  =  new  RemoteWebDriver ( new  URL ( "http://www.example.com" ),  chromeOptions ); 
driver . get ( "http://www.google.com" ); 
driver . quit (); 
    
     
    
        from  selenium  import  webdriver 
 chrome_options  =  webdriver . ChromeOptions () 
chrome_options . set_capability ( "browserVersion" ,  "67" ) 
chrome_options . set_capability ( "platformName" ,  "Windows XP" ) 
driver  =  webdriver . Remote ( 
    command_executor = 'http://www.example.com' , 
     options = chrome_options 
 ) 
driver . get ( "http://www.google.com" ) 
driver . quit ()   
    
     
    
        var  chromeOptions  =  new  ChromeOptions (); 
chromeOptions . BrowserVersion  =  "67" ; 
chromeOptions . PlatformName  =  "Windows XP" ; 
IWebDriver  driver  =  new  RemoteWebDriver ( new  Uri ( "http://www.example.com" ),  chromeOptions ); 
driver . Navigate (). GoToUrl ( "http://www.google.com" ); 
driver . Quit (); 
    
     
    
        caps  =  Selenium :: WebDriver :: Remote :: Capabilities . chrome 
caps . platform  =  Windows  XP 
caps . version  =  67 
 driver  =  Selenium :: WebDriver . for  :remote ,  :url  =>  "http://www.example.com" ,  :desired_capabilities  =>  caps 
    
     
    
        const  {  Builder  }  =  require ( "selenium-webdriver" ); 
const  chrome  =  require ( "selenium-webdriver/chrome" ); 
let  opts  =  new  chrome . Options (); 
opts . setAcceptInsecureCerts ( true ); 
opts . setBrowserVersion ( '67' ); 
opts . setPlatform ( 'Windows XP' ); 
( async  function  helloSelenium ()  { 
    let  driver  =  new  Builder () 
         . usingServer ( "http://example.com" ) 
         . forBrowser ( 'chrome' ) 
         . setChromeOptions ( opts ) 
         . build (); 
     try  { 
         await  driver . get ( 'http://www.google.com' ); 
     } 
     finally  { 
         await  driver . quit (); 
     } 
 })();  
  
  
     
    
        val  chromeOptions  =  ChromeOptions () 
chromeOptions . setCapability ( "browserVersion" ,  "67" ) 
chromeOptions . setCapability ( "platformName" ,  "Windows XP" ) 
val  driver :  WebDriver  =  new  RemoteWebDriver ( new  URL ( "http://www.example.com" ),  chromeOptions ) 
driver . get ( "http://www.google.com" ) 
driver . quit () 
    
     
 
ローカルファイルDetector 
ローカルファイルDetectorを使用すると、クライアントマシンからリモートサーバーにファイルを転送できます。
例えば、テストでファイルをWebアプリケーションにアップロードする必要がある場合、リモートWebDriverは実行時にローカルマシンからリモートWebサーバーにファイルを自動的に転送できます。
これにより、テストを実行しているリモートマシンからファイルをアップロードできます。
デフォルトでは有効になっておらず、次の方法で有効にできます。
  
  
  
  
  
  
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        driver . setFileDetector ( new  LocalFileDetector ()); 
    
     
    
        from  selenium.webdriver.remote.file_detector  import  LocalFileDetector 
 driver . file_detector  =  LocalFileDetector () 
    
     
    
        var  allowsDetection  =  this . driver  as  IAllowsFileDetection ; 
if  ( allowsDetection  !=  null ) 
{ 
   allowsDetection . FileDetector  =  new  LocalFileDetector (); 
 } 
    
     
    
        @driver . file_detector  =  lambda  do  | args | 
  # args => ["/path/to/file"] 
   str  =  args . first . to_s 
   str  if  File . exist? ( str ) 
 end 
    
     
    
        var  remote  =  require ( 'selenium-webdriver/remote' ); 
driver . setFileDetector ( new  remote . FileDetector );    
  
  
     
    
        driver . fileDetector  =  LocalFileDetector () 
    
     
 
上記のコードを定義したら、次の方法でテストにファイルをアップロードできます。
  
  
  
  
  
  
  
      
        Java
       
     
      
        Python
       
     
      
        CSharp
       
     
      
        Ruby
       
     
      
        JavaScript
       
     
      
        Kotlin
       
     
 
    
        driver . get ( "http://sso.dev.saucelabs.com/test/guinea-file-upload" ); 
WebElement  upload  =  driver . findElement ( By . id ( "myfile" )); 
upload . sendKeys ( "/Users/sso/the/local/path/to/darkbulb.jpg" ); 
    
     
    
        driver . get ( "http://sso.dev.saucelabs.com/test/guinea-file-upload" ) 
 driver . find_element ( By . ID ,  "myfile" ) . send_keys ( "/Users/sso/the/local/path/to/darkbulb.jpg" ) 
    
     
    
        driver . Navigate (). GoToUrl ( "http://sso.dev.saucelabs.com/test/guinea-file-upload" ); 
IWebElement  upload  =  driver . FindElement ( By . Id ( "myfile" )); 
upload . SendKeys ( @"/Users/sso/the/local/path/to/darkbulb.jpg" ); 
    
     
    
        @driver . navigate . to  "http://sso.dev.saucelabs.com/test/guinea-file-upload" 
    element  =  @driver . find_element ( :id ,  'myfile' ) 
     element . send_keys  "/Users/sso/SauceLabs/sauce/hostess/maitred/maitred/public/images/darkbulb.jpg" 
     
     
    
        driver . get ( "http://sso.dev.saucelabs.com/test/guinea-file-upload" ); 
var  upload  =  driver . findElement ( By . id ( "myfile" )); 
upload . sendKeys ( "/Users/sso/the/local/path/to/darkbulb.jpg" );   
  
  
     
    
        driver . get ( "http://sso.dev.saucelabs.com/test/guinea-file-upload" ) 
val  upload :  WebElement  =  driver . findElement ( By . id ( "myfile" )) 
upload . sendKeys ( "/Users/sso/the/local/path/to/darkbulb.jpg" ) 
    
     
 
クライアントのリクエストをトレースする 
この機能は、Java クライアント バインディング (ベータ版以降) でのみ利用できます。
Remote WebDriver クライアントは Selenium Grid サーバーにリクエストを送信し、
Selenium Grid サーバーはリクエストを WebDriver に渡します。
HTTP リクエストをエンド ツー エンドでトレースするには、サーバー側とクライアント側でトレースを有効にする必要があります。
両端には、視覚化フレームワークを指すトレース エクスポーターのセットアップが必要です。
デフォルトでは、トレースはクライアントとサーバーの両方で有効になっています。
視覚化フレームワークの Jaeger UI と Selenium Grid 4 を設定するには、目的のバージョンの
トレースのセットアップ  を参照してください。
クライアント側のセットアップについては、以下の手順に従ってください。
必要な依存関係を追加する 
トレーシング エクスポーターの外部ライブラリのインストールは、Maven を使って実行できます。
プロジェクト pom.xml に opentelemetry-exporter-jaeger  および grpc-netty  の依存関係を追加します。
  <dependency> 
       <groupId> io.opentelemetry</groupId> 
       <artifactId> opentelemetry-exporter-jaeger</artifactId> 
       <version> 1.0.0</version> 
     </dependency> 
     <dependency> 
       <groupId> io.grpc</groupId> 
       <artifactId> grpc-netty</artifactId> 
       <version> 1.35.0</version> 
     </dependency> 
 クライアントの実行中に必要なシステムプロパティを追加/渡す 
  
    
        System . setProperty ( "otel.traces.exporter" ,  "jaeger" ); 
System . setProperty ( "otel.exporter.jaeger.endpoint" ,  "http://localhost:14250" ); 
System . setProperty ( "otel.resource.attributes" ,  "service.name=selenium-java-client" ); 
 ImmutableCapabilities  capabilities  =  new  ImmutableCapabilities ( "browserName" ,  "chrome" ); 
 WebDriver  driver  =  new  RemoteWebDriver ( new  URL ( "http://www.example.com" ),  capabilities ); 
 driver . get ( "http://www.google.com" ); 
 driver . quit (); 
     
     
 
ご希望のSeleniumのバージョンに必要な外部依存関係のバージョンの詳細については、
トレースのセットアップ  を参照してください。
詳細については、下記URLを参照してください。
Browser specific functionalities 
Some browser specific functionalities  require workarounds as mentioned in this issue .