Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Interacting with Webpage - Selenium Python
Next article icon

Selenium's Python module allows you to automate web testing usingPython. The Selenium Python bindings provide a straightforward API to write functional and acceptance tests with Selenium WebDriver. Through this API, you can easily access all WebDriver features in a user-friendly way. This article explains how to use Selenium with Python to navigate to a web page using the get() method of Selenium WebDriver. If you have not installed Selenium and its components yet, install them from hereSelenium Python Introduction and Installation

What is the get() method ?

get()method in Selenium WebDriver is used to load a web page by navigating to the provided URL. When you call this method, WebDriver will send a GET request to the server and load the page. The WebDriver will wait for the page to fully load before giving control back to your script.

Syntax:

driver.get("url")

Step-by-Step Implementation

1. Install Selenium (if not already installed):

pip install selenium

2. Create a Python script named run.py:

from selenium import webdriver


# Initialize WebDriver (e.g., Firefox or Chrome)

driver = webdriver.Firefox()


# Open Google

driver.get("https://www.google.com//")


# Close browser

driver.quit()

Example:

Python
fromseleniumimportwebdriverfromselenium.webdriver.common.byimportByfromselenium.webdriver.common.keysimportKeysimporttime# Launch browser and open Googledrv=webdriver.Chrome()drv.get("https://www.google.com//")# Search "GeeksforGeeks"box=drv.find_element(By.NAME,"q")box.send_keys("GeeksforGeeks",Keys.RETURN)# Wait and close browsertime.sleep(5)drv.quit()

Output

Navigating links using get method

Explanation: This code opens a browser and goes to a website. It finds the search input field and types in a query. Then, it submits the query to perform a search. After waiting a few seconds for the results to load, it closes the browser.


Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp