Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Selenium Tutorial

Selenium Tutorial

Selenium is a toolset for automating web browser operations.

Selenium is mainly used for the automated testing of web applications.

Selenium supports multiple programming languages (such as Python, Java, C#, JavaScript, etc.) and can run on various browsers (such as Chrome, Firefox, Edge, Safari, etc.) and operating systems (such as Windows, macOS, Linux).

The core function of Selenium is to simulate user operations in the browser, such as clicking buttons, entering text, and navigating pages.

Who should read this tutorial?

Selenium is a powerful automation testing tool, suitable for the automated testing of web applications and other browser automation tasks.

Through Selenium, you can write scripts to simulate user operations in the browser, thereby improving testing efficiency.

Knowledge you need before reading this tutorial:


Learning path

  1. Learn programming basics(e.g., Python or Java).

  2. Learn web development basics (HTML, CSS, JavaScript).

  3. Get familiar with browser developer tools.

  4. Learn Selenium basics(environment setup, element location, element operations).

  5. Hands-on projects(e.g., automated login, form submission, data scraping, etc.).

  6. Learn advanced topics(e.g., wait mechanisms, browser operations, test framework integration).


Write your first Selenium script

Below is a simple Selenium script example written in Python; it opens the Chrome browser, navigates to Baidu's homepage, types "Runoob" into the search box, and clicks the search button.

Example

from

selenium

import

webdriver

from

selenium.

webdriver

.

common

.

keys

import

Keys

Create a Chrome WebDriver instance

driver

=

webdriver.

Chrome

(

)

Open the Baidu home page

driver.

get

(

"https://www.baidu.com"

)

Find the search box element

search_box

=

driver.

find_element_by_name

(

"wd"

)

Type "Runoob" into the search box

search_box.

send_keys

(

"Runoob"

)

Simulate pressing the Enter key

search_box.

send_keys

(

Keys.

RETURN

)

Close the browser

driver.

quit

(

)

Code Analysis


Related links

Official site:https://www.selenium.dev/

Selenium download:https://www.selenium.dev/downloads/

Selenium Chinese documentation: https://www.selenium.dev/zh-cn/documentation/

GitHub open source address:https://github.com/SeleniumHQ