|
| 1 | +--- |
| 2 | +title: "The Selenium Browser Automation Project" |
| 3 | +linkTitle: "Documentation" |
| 4 | +cascade: |
| 5 | +- type: docs |
| 6 | +aliases: ["/documentation/nl/"] |
| 7 | +--- |
| 8 | + |
| 9 | +{{% pageinfo color="warning" %}} |
| 10 | +<p class="lead"> |
| 11 | + <i class="fas fa-language display-4"></i> |
| 12 | + Page being translated from |
| 13 | + English to Dutch. Do you speak Dutch? Help us to translate |
| 14 | + it by sending us pull requests! |
| 15 | +</p> |
| 16 | +{{% /pageinfo %}} |
| 17 | + |
| 18 | +Selenium is an umbrella project for a range of tools and libraries |
| 19 | +that enable and support the automation of web browsers. |
| 20 | + |
| 21 | +It provides extensions to emulate user interaction with browsers, |
| 22 | +a distribution server for scaling browser allocation, |
| 23 | +and the infrastructure for implementations of the |
| 24 | +[W3C WebDriver specification](//www.w3.org/TR/webdriver/) |
| 25 | +that lets you write interchangeable code for all major web browsers. |
| 26 | + |
| 27 | +This project is made possible by volunteer contributors |
| 28 | +who have put in thousands of hours of their own time, |
| 29 | +and made the source code |
| 30 | +[freely available]({{< ref "/copyright_and_attributions.md#license" >}}) |
| 31 | +for anyone to use, enjoy, and improve. |
| 32 | + |
| 33 | +Selenium brings together browser vendors, engineers, and enthusiasts |
| 34 | +to further an open discussion around automation of the web platform. |
| 35 | +The project organises [an annual conference](//seleniumconf.com/) |
| 36 | +to teach and nurture the community. |
| 37 | + |
| 38 | +At the core of Selenium is [WebDriver](/documentation/webdriver), |
| 39 | +an interface to write instruction sets that can be run interchangeably in many |
| 40 | +browsers. Here is one of the simplest instructions you can make: |
| 41 | + |
| 42 | +{{< tabpane langEqualsHeader=true >}} |
| 43 | + {{< tab header="Java" >}} |
| 44 | +import org.openqa.selenium.By; |
| 45 | +import org.openqa.selenium.Keys; |
| 46 | +import org.openqa.selenium.WebDriver; |
| 47 | +import org.openqa.selenium.WebElement; |
| 48 | +import org.openqa.selenium.firefox.FirefoxDriver; |
| 49 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 50 | +import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; |
| 51 | +import java.time.Duration; |
| 52 | + |
| 53 | +public class HelloSelenium { |
| 54 | + |
| 55 | + public static void main(String[] args) { |
| 56 | + WebDriver driver = new FirefoxDriver(); |
| 57 | + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); |
| 58 | + try { |
| 59 | + driver.get("https://google.com/ncr"); |
| 60 | + driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER); |
| 61 | + WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3"))); |
| 62 | + System.out.println(firstResult.getAttribute("textContent")); |
| 63 | + } finally { |
| 64 | + driver.quit(); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + {{< /tab >}} |
| 69 | + {{< tab header="Python" >}} |
| 70 | +from selenium import webdriver |
| 71 | +from selenium.webdriver.common.by import By |
| 72 | +from selenium.webdriver.common.keys import Keys |
| 73 | +from selenium.webdriver.support.ui import WebDriverWait |
| 74 | +from selenium.webdriver.support.expected_conditions import presence_of_element_located |
| 75 | + |
| 76 | +#This example requires Selenium WebDriver 3.13 or newer |
| 77 | +with webdriver.Firefox() as driver: |
| 78 | + wait = WebDriverWait(driver, 10) |
| 79 | + driver.get("https://google.com/ncr") |
| 80 | + driver.find_element(By.NAME, "q").send_keys("cheese" + Keys.RETURN) |
| 81 | + first_result = wait.until(presence_of_element_located((By.CSS_SELECTOR, "h3"))) |
| 82 | + print(first_result.get_attribute("textContent")) |
| 83 | + {{< /tab >}} |
| 84 | + {{< tab header="CSharp" >}} |
| 85 | +using System; |
| 86 | +using OpenQA.Selenium; |
| 87 | +using OpenQA.Selenium.Firefox; |
| 88 | +using OpenQA.Selenium.Support.UI; |
| 89 | + |
| 90 | +class HelloSelenium { |
| 91 | + static void Main() { |
| 92 | + using(IWebDriver driver = new FirefoxDriver()) { |
| 93 | + WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); |
| 94 | + driver.Navigate().GoToUrl("https://www.google.com/ncr"); |
| 95 | + driver.FindElement(By.Name("q")).SendKeys("cheese" + Keys.Enter); |
| 96 | + wait.Until(webDriver => webDriver.FindElement(By.CssSelector("h3")).Displayed); |
| 97 | + IWebElement firstResult = driver.FindElement(By.CssSelector("h3")); |
| 98 | + Console.WriteLine(firstResult.GetAttribute("textContent")); |
| 99 | + } |
| 100 | + } |
| 101 | +} |
| 102 | + {{< /tab >}} |
| 103 | + {{< tab header="Ruby" >}} |
| 104 | +require 'selenium-webdriver' |
| 105 | + |
| 106 | +driver = Selenium::WebDriver.for :firefox |
| 107 | +wait = Selenium::WebDriver::Wait.new(timeout: 10) |
| 108 | + |
| 109 | +begin |
| 110 | + driver.get 'https://google.com/ncr' |
| 111 | + driver.find_element(name: 'q').send_keys 'cheese', :return |
| 112 | + first_result = wait.until { driver.find_element(css: 'h3') } |
| 113 | + puts first_result.attribute('textContent') |
| 114 | +ensure |
| 115 | + driver.quit |
| 116 | +end |
| 117 | + {{< /tab >}} |
| 118 | + {{< tab header="JavaScript" >}} |
| 119 | +const {Builder, By, Key, until} = require('selenium-webdriver'); |
| 120 | + |
| 121 | +(async function example() { |
| 122 | + let driver = await new Builder().forBrowser('firefox').build(); |
| 123 | + try { |
| 124 | + // Navigate to Url |
| 125 | + await driver.get('https://www.google.com'); |
| 126 | + |
| 127 | + // Enter text "cheese" and perform keyboard action "Enter" |
| 128 | + await driver.findElement(By.name('q')).sendKeys('cheese', Key.ENTER); |
| 129 | + |
| 130 | + let firstResult = await driver.wait(until.elementLocated(By.css('h3')), 10000); |
| 131 | + |
| 132 | + console.log(await firstResult.getAttribute('textContent')); |
| 133 | + } |
| 134 | + finally{ |
| 135 | + await driver.quit(); |
| 136 | + } |
| 137 | +})(); |
| 138 | + {{< /tab >}} |
| 139 | + {{< tab header="Kotlin" >}} |
| 140 | +import org.openqa.selenium.By |
| 141 | +import org.openqa.selenium.Keys |
| 142 | +import org.openqa.selenium.firefox.FirefoxDriver |
| 143 | +import org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated |
| 144 | +import org.openqa.selenium.support.ui.WebDriverWait |
| 145 | +import java.time.Duration |
| 146 | + |
| 147 | +fun main() { |
| 148 | + val driver = FirefoxDriver() |
| 149 | + val wait = WebDriverWait(driver, Duration.ofSeconds(10)) |
| 150 | + try { |
| 151 | + driver.get("https://google.com/ncr") |
| 152 | + driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER) |
| 153 | + val firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3"))) |
| 154 | + println(firstResult.getAttribute("textContent")) |
| 155 | + } finally { |
| 156 | + driver.quit() |
| 157 | + } |
| 158 | +} |
| 159 | + {{< /tab >}} |
| 160 | +{{< /tabpane >}} |
| 161 | + |
| 162 | +See the [Overview]({{< ref "/overview.md" >}}) to check the different project |
| 163 | +components and decide if Selenium is the right tool for you. |
| 164 | + |
| 165 | +You should continue on to [Getting Started]({{< ref "/getting_started.md" >}}) |
| 166 | +to understand how you can install Selenium and successfully use it as a test |
| 167 | +automation tool, and scaling simple tests like this to run in large, distributed |
| 168 | +environments on multiple browsers, on several different operating systems. |
| 169 | + |
| 170 | + |
| 171 | + |
0 commit comments