top of page
back.jpg

getText() method - Python Selenium Automation Testing

What is the role of the `getText` method and how this method is utilized to fetch and display the text content from webelement

# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

# Create a Service object for the Chrome browser
service_obj = Service()

# Initialize the Chrome WebDriver with the created Service
driver = webdriver.Chrome(service=service_obj)

# Open the specified website
driver.get("https://the-internet.herokuapp.com/")

# Maximize the browser window
driver.maximize_window()

# Set an implicit wait of 3 seconds to allow elements to be found
driver.implicitly_wait(3)

# Find and print the text of the first <h1> element on the page
h1_element_text = driver.find_element(By.TAG_NAME, "h1").text
print(h1_element_text)

# Close the browser window
driver.quit()

17 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a success message is displayed. package com.seleniumExamples2024; pu

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl + P: Print Ctrl + F: Find Windows Shortcuts: Windows Key: Open or

Commentaires

Noté 0 étoile sur 5.
Pas encore de note

Ajouter une note
bottom of page