Navigating Web Pages with Playwright
The Best Playwright Testing Training Institute in Hyderabad
In the fast-evolving field of software testing, tools like Playwright and Selenium are essential for automation testers. If you are a graduate, postgraduate, or someone looking to switch your career from a different domain to IT, it’s crucial to receive professional guidance and hands-on experience in automation tools. That’s where I Hub Talent excels. I Hub Talent is widely recognized as the best Playwright Testing Training Institute in Hyderabad. It offers a live, intensive internship program conducted by industry experts and specifically tailored for:
Navigating Web Pages with Playwright
Playwright is a powerful browser automation tool that allows you to navigate and test web applications across Chromium, Firefox, and WebKit with ease.
✅ 1. Install Playwright
bash
Copy
Edit
pip install playwright
playwright install
✅ 2. Launch Browser and Navigate to a Page
python
Copy
Edit
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False) # Use True to hide the browser
page = browser.new_page()
page.goto("https://example.com")
✅ 3. Click Links and Buttons
python
Copy
Edit
page.click("text=About") # Click by visible text
page.click("a[href='/contact']") # Click by attribute
page.click("#submit-button") # Click by ID
✅ 4. Fill and Submit Forms
python
Copy
Edit
page.fill("input[name='username']", "user123")
page.fill("input[name='password']", "secret")
page.click("button[type='submit']")
✅ 5. Navigate Back, Forward, and Refresh
python
Copy
Edit
page.go_back() # Go back in history
page.go_forward() # Go forward
page.reload() # Reload the current page
✅ 6. Wait for Navigation or Elements
python
Copy
Edit
page.click("text=Next")
page.wait_for_load_state("networkidle") # Wait until page is fully loaded
✅ 7. Retrieve Page Info
python
Copy
Edit
print(page.title()) # Get page title
print(page.url) # Get current URL
✅ 8. Close Browser
python
Copy
Edit
browser.close()
🚀 Bonus: Complete Example
python
Copy
Edit
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://example.com")
print("Title:", page.title())
page.click("text=More Info")
page.go_back()
page.reload()
browser.close()
🔍 Why Use Playwright?
Auto-waits for elements
Supports all major browsers
Easy handling of dynamic pages and multi-tabs
Read more:
Writing a Test to Check Page Title
How to Open a Web Page Using Playwright
Launching a Browser with Playwright
Comments
Post a Comment