Handling UI Elements: TextBox, Button, & Checkbox | Advanced Playwright TypeScript Tutorial | Part VI

:rocket: Hey folks!

Check out our latest tutorial: Handling UI Elements: TextBox, Button, & Checkbox | Advanced Playwright TypeScript Tutorial | Part VI:movie_camera:

Master the art of handling key UI elements like text boxes, buttons, and checkboxes using Playwright with TypeScript. This video is packed with actionable tips to elevate your test automation skills! :bulb:

:point_right: Watch now and take your testing game to the next level!

Using Selenium WebDriver (Python) With Selenium WebDriver, you can easily interact with UI elements like TextBox, Button, and Checkbox. Here’s how you can handle each element:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

Set up the WebDriver

driver = webdriver.Chrome()

Open the desired web page

driver.get(“https://yourwebsite.com”)

Handling TextBox

textbox = driver.find_element(By.ID, "textbox_id")
textbox.send_keys("Some text")

Handling Button

button = driver.find_element(By.ID, "button_id")
button.click()

Handling Checkbox

checkbox = driver.find_element(By.ID, "checkbox_id")
if not checkbox.is_selected():
    checkbox.click()

Close the browser

driver.quit()

Using Playwright (Python) Playwright offers an alternative way to handle UI elements. Here’s how you can work with TextBox, Button, and Checkbox:

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()

Navigate to the page

page.goto("https://yourwebsite.com")

Handling TextBox

page.fill("#textbox_id", "Some text")

Handling Button

page.click("#button_id")

Handling Checkbox

 if not page.is_checked("#checkbox_id"):
        page.check("#checkbox_id")

Close the browser

browser.close()

Using PyAutoGUI for Desktop Applications

If you’re working with desktop applications and need to handle UI elements such as TextBox, Button, and Checkbox, PyAutoGUI can help simulate user actions:

import pyautogui

Handling TextBox (assuming the focus is already on the text box)

pyautogui.typewrite(“Some text”)

Handling Button (assuming the button is in a clickable position)

pyautogui.click(x=100, y=200) # Replace with actual coordinates of the button

Handling Checkbox (assuming the checkbox is at a certain position)

pyautogui.click(x=150, y=250) # Replace with actual coordinates of the checkbox