Seleniumライブラリのインストール
お気に入りのプログラミング言語用にSeleniumライブラリを設定します。
最初にあなたの自動化プロジェクトにSeleniumのバインディングをインストールする必要があります。
インストールの方法は選択した言語によって異なります。
言語別の要件
サポートされている最小のJavaバージョンを表示する ここ.
Java用のSeleniumライブラリのインストールは、ビルドツールを使用して行います。
Maven
プロジェクトの ‘pom.xml’ ファイルで依存関係を指定します:
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"><?xml version="1.0" encoding="UTF-8"?></span>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.selenium</groupId>
<artifactId>selenium-examples</artifactId>
<version>1.0.0</version>
<properties>
<surefire.parallel>1</surefire.parallel>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<selenium.version>4.31.0</selenium.version>
</properties>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-grid</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.12.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.titusfortner</groupId>
<artifactId>selenium-logger</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.config.strategy = fixed
junit.jupiter.execution.parallel.config.fixed.parallelism = ${surefire.parallel}
junit.jupiter.execution.parallel.config.fixed.max-pool-size = ${surefire.parallel}
</configurationParameters>
</properties>
<rerunFailingTestsCount>3</rerunFailingTestsCount>
</configuration>
</plugin>
</plugins>
</build>
</project>
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/java/pom.xml#L30-L34" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
Gradle
プロジェクトの ‘build.gradle’ ファイル内の依存関係を ’testImplementation’ として指定します:
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-gradle" data-lang="gradle"><span style="display:flex;"><span><span style="color:#000">plugins</span> <span style="color:#ce5c00;font-weight:bold">{</span>
id 'java'
}
group 'dev.selenium'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.seleniumhq.selenium:selenium-java:4.31.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.12.1'
}
test {
useJUnitPlatform()
}
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/java/build.gradle#L13-L14" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
各 Selenium バージョンでサポートされている最小 Python バージョンについては、次の場所にあります サポートされている Python バージョン
オン PyPi。
Seleniumをインストールするには、いくつかの方法があります。
Pip
ダウンロード
または、ダウンロードすることもできますPyPI ソースアーカイブ
(selenium-x.x.x.-py3-none-any.whl) を使用してインストールします pip:
pip install selenium-x.x.x.-py3-none-any.whl
プロジェクトで必要
プロジェクトで使用するには、requirements.txt ファイルに追加します:
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>selenium==4.31.0
pytest==8.3.5
trio==0.29.0
pytest-trio==0.8.0
pytest-rerunfailures==15.0
flake8==7.2.0
requests==2.32.3
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/python/requirements.txt#L1" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
Seleniumの各バージョンでサポートされているすべてのフレームワークのリスト
で利用可能ですNuget
Seleniumのインストールにはいくつかのオプションがあります。
パケットマネージャー
Install-Package Selenium.WebDriver
.NET CLI
dotnet add package Selenium.WebDriver
CSProj
プロジェクトの csproj
ファイルで、ItemGroup
の PackageReference
として依存関係を指定します。:
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-csproj" data-lang="csproj"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold"><Project</span> <span style="color:#c4a000">Sdk=</span><span style="color:#4e9a06">"Microsoft.NET.Sdk"</span><span style="color:#204a87;font-weight:bold">></span>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.0" />
<PackageReference Include="Selenium.Support" Version="4.31.0" />
<PackageReference Include="Selenium.WebDriver" Version="4.31.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="LocalPackages" />
</ItemGroup>
</Project>
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/dotnet/SeleniumDocs/SeleniumDocs.csproj#L14" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
その他の考慮事項
その他、使用上の注意点 Visual Studio Code (vscode) そして C#
上記のセクションに従って、互換性のある .NET SDK をインストールします。
また、C# と NuGet の vscode 拡張機能 (Ctrl-Shift-X) もインストールします。に従ってください指示はこちら
C# を使用して “Hello World” コンソール プロジェクトを作成および実行します。
コマンドラインを使用してNUnitスタータープロジェクトを作成することもできます dotnet new NUnit
.
ファイルを確認してください %appdata%\NuGet\nuget.config
一部の開発者がいくつかの問題のために空になると報告したため、適切に構成されています。
もしnuget.config
が空であるか、正しく構成されていない場合、Selenium プロジェクトの .NET ビルドは失敗します。
次のセクションをファイルに追加しますnuget.config
空の場合:
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
...
詳細については、nuget.config
ここをクリック.
カスタマイズする必要があるかもしれません nuget.config
あなたのニーズを満たすために。
さて、戻ってください vscode、プレス Ctrl-Shift-P、およびタイプ “NuGet Add Package"をクリックし、必要な Selenium パッケージ Selenium.WebDriver
.
Enter キーを押して、バージョンを選択します。
これで、C# と vscode に関連するドキュメントの例を使用できるようになりました。
特定の Selenium バージョンに対して最低限必要な Ruby のバージョンを確認できます
オン rubygems.org
Seleniumは2つの異なる方法でインストールできます。
手動でインストールする
gem install selenium-webdriver
プロジェクトの gemfile に追加
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Gemfile" data-lang="Gemfile"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># frozen_string_literal: true</span>
source 'https://rubygems.org'
gem 'ffi', '~> 1.15', '>= 1.15.5' if Gem.win_platform? # Windows only
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.0'
gem 'rubocop', '~> 1.35'
gem 'rubocop-rspec', '~> 3.0'
gem 'selenium-devtools', '= 0.135.0'
gem 'selenium-webdriver', '= 4.31.0'
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/ruby/Gemfile#L10" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
Seleniumの特定のバージョンに最低限必要なNodeのバージョンは、Node Support Policy
節 オン npmjs
Seleniumは通常、npmを使用してインストールされます。
ローカルにインストールする
npm install selenium-webdriver
プロジェクトに加える
プロジェクトの package.json
で、要件を dependencies
:
<details class="mt-3">
<summary>Show full example</summary>
<div class="pt-2">
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
"name": "javascript-examples",
"version": "1.0.0",
"scripts": {
"test": "npx mocha test/**/*.spec.js –timeout 90000"
},
"author": "The Selenium project",
"license": "Apache-2.0",
"dependencies": {
"assert": "2.1.0",
"selenium-webdriver": "4.31.0"
},
"devDependencies": {
"mocha": "11.1.0"
}
}
<div class="text-end pb-2 mt-2">
<a href="https://github.com/SeleniumHQ/seleniumhq.github.io/blob/display_full/examples/javascript/package.json#L14" target="_blank">
<i class="fas fa-external-link-alt pl-2"></i>
<strong>View full example on GitHub</strong>
</a>
</div>
Kotlin の Java バインディングを使用します。
次のステップ
初めてのSeleniumスクリプトを作成する
Development Partners
Selenium Level Sponsors
Support the Selenium Project
Learn more or view the full list of sponsors.