1- # 🎭 [ Playwright] ( https://playwright.dev ) for Python [ ![ PyPI version] ( https://badge.fury.io/py/playwright.svg )] ( https://pypi.python.org/pypi/playwright/ ) [ ![ Anaconda version] ( https://img.shields.io/conda/v/microsoft/playwright )] ( https://anaconda.org/Microsoft/playwright ) [ ![ Join Discord] ( https://img.shields.io/badge/join-discord-infomational )] ( https://aka.ms/playwright/discord )
1+ # 🎭 [ Playwright] ( https://playwright.dev ) for Python
2+ [ ![ PyPI version] ( https://badge.fury.io/py/playwright.svg )] ( https://pypi.python.org/pypi/playwright/ )
3+ [ ![ Anaconda version] ( https://img.shields.io/conda/v/microsoft/playwright )] ( https://anaconda.org/Microsoft/playwright )
4+ [ ![ Join Discord] ( https://img.shields.io/badge/join-discord-infomational )] ( https://aka.ms/playwright/discord )
25
3- Playwright is a Python library to automate [ Chromium] ( https://www.chromium.org/Home ) , [ Firefox] ( https://www.mozilla.org/en-US/firefox/new/ ) and [ WebKit] ( https://webkit.org/ ) browsers with a single API. Playwright delivers automation that is ** ever-green** , ** capable** , ** reliable** and ** fast** . [ See how Playwright is better] ( https://playwright.dev/python ) .
6+ Playwright is a powerful Python library to automate [ Chromium] ( https://www.chromium.org/Home ) , [ Firefox] ( https://www.mozilla.org/en-US/firefox/new/ ) and [ WebKit] ( https://webkit.org/ ) browsers with a single API. Playwright delivers automation that is ** ever-green** , ** capable** , ** reliable** and ** fast** . [ See how Playwright is better] ( https://playwright.dev/python ) .
47
5- | | Linux | macOS | Windows |
6- | :--- | :---: | :---: | :---: |
7- | Chromium <!-- GEN:chromium-version --> 141.0.7390.37<!-- GEN:stop --> | ✅ | ✅ | ✅ |
8- | WebKit <!-- GEN:webkit-version --> 26.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
9- | Firefox <!-- GEN:firefox-version --> 142.0.1<!-- GEN:stop --> | ✅ | ✅ | ✅ |
8+ ## 🌟 Key Features
109
11- ## Documentation
10+ - ** Cross-browser** : Automate Chromium, Firefox, and WebKit with the same API
11+ - ** Cross-platform** : Works on Windows, macOS, and Linux
12+ - ** Cross-language** : Same API available in Python, JavaScript, .NET, and Java
13+ - ** Auto-waiting** : Automatically waits for elements to be ready
14+ - ** Mobile emulation** : Test responsive web apps with mobile device simulation
15+ - ** Network interception** : Capture and modify network requests
16+ - ** Reliable selectors** : Built-in support for text, CSS, XPath, and React selectors
1217
13- [ https://playwright.dev/python/docs/intro ] ( https://playwright.dev/python/docs/intro )
18+ ## 🚀 Quick Start
1419
15- ## API Reference
20+ ### Installation
1621
17- [ https://playwright.dev/python/docs/api/class-playwright ] ( https://playwright.dev/python/docs/api/class-playwright )
22+ ``` bash
23+ # Install Playwright
24+ pip install playwright
1825
19- ## Example
26+ # Install browser binaries (Chrome, Firefox, WebKit)
27+ playwright install
28+ ```
29+
30+ ### Your First Script
31+
32+ Create a file ` example.py ` :
2033
21- ``` py
34+ ``` python
35+ from playwright.sync_api import sync_playwright
36+
37+ def main ():
38+ with sync_playwright() as p:
39+ # Launch browser
40+ browser = p.chromium.launch(headless = False )
41+ page = browser.new_page()
42+ page.goto(' https://playwright.dev' )
43+ page.screenshot(path = ' example.png' )
44+ print (f " Page title: { page.title()} " )
45+ browser.close()
46+
47+ if __name__ == " __main__" :
48+ main()
49+ ```
50+
51+ Run your script:
52+ ``` bash
53+ python example.py
54+ ```
55+
56+ ## 📚 Examples
57+
58+ ### Sync API
59+
60+ ``` python
2261from playwright.sync_api import sync_playwright
2362
2463with sync_playwright() as p:
@@ -27,10 +66,13 @@ with sync_playwright() as p:
2766 page = browser.new_page()
2867 page.goto(' http://playwright.dev' )
2968 page.screenshot(path = f ' example- { browser_type.name} .png ' )
69+ print (f " Screenshot saved: example- { browser_type.name} .png " )
3070 browser.close()
3171```
3272
33- ``` py
73+ ### Async API
74+
75+ ``` python
3476import asyncio
3577from playwright.async_api import async_playwright
3678
@@ -41,14 +83,109 @@ async def main():
4183 page = await browser.new_page()
4284 await page.goto(' http://playwright.dev' )
4385 await page.screenshot(path = f ' example- { browser_type.name} .png ' )
86+ print (f " Screenshot saved: example- { browser_type.name} .png " )
4487 await browser.close()
4588
4689asyncio.run(main())
4790```
4891
49- ## Other languages
92+ ## 🛠️ Installation Guide
93+
94+ ### Prerequisites
95+ - Python 3.7 or higher
96+ - pip package manager
97+ - Node.js 14 or higher
98+
99+ ### Step-by-Step Setup
100+
101+ 1 . ** Create virtual environment** (recommended):
102+ ``` bash
103+ python -m venv playwright-env
104+ source playwright-env/bin/activate
105+ ```
106+
107+ 2 . ** Install Playwright** :
108+ ``` bash
109+ pip install playwright
110+ ```
111+
112+ 3 . ** Install browsers** :
113+ ``` bash
114+ playwright install
115+ ```
116+
117+ ### Installation Options
118+
119+ - ** Specific browser** :
120+ ``` bash
121+ playwright install chromium
122+ playwright install firefox
123+ ```
124+
125+ - ** With conda** :
126+ ``` bash
127+ conda install -c conda-forge playwright
128+ ```
129+
130+ ## 🌐 Supported Browsers
131+
132+ | Browser | Linux | macOS | Windows |
133+ | -----------| -------| -------| ---------|
134+ | Chromium | ✅ | ✅ | ✅ |
135+ | WebKit | ✅ | ✅ | ✅ |
136+ | Firefox | ✅ | ✅ | ✅ |
137+
138+ ## ❓ Troubleshooting
139+
140+ ** "playwright: command not found"**
141+ - Use: ` python -m playwright ` instead of ` playwright `
142+
143+ ** Browser installation fails**
144+ - Check internet connection
145+ - Try: ` playwright install --force `
146+
147+ ** Permission errors**
148+ - Use: ` sudo playwright install `
149+
150+ ## 📖 Learning Resources
151+
152+ - [ Documentation] ( https://playwright.dev/python/docs/intro )
153+ - [ API Reference] ( https://playwright.dev/python/docs/api/class-playwright )
154+ - [ Examples] ( https://playwright.dev/python/docs/examples )
155+
156+ ## 🌍 Other Languages
157+
158+ - [ Node.js] ( https://playwright.dev/docs/intro )
159+ - [ .NET] ( https://playwright.dev/dotnet/docs/intro )
160+ - [ Java] ( https://playwright.dev/java/docs/intro )
161+
162+ ## 🤝 Contributing
163+
164+ We welcome contributions from the community! Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated.
165+
166+ ### How to Contribute
167+
168+ 1 . ** Fork the repository**
169+ 2 . ** Create a feature branch** : ` git checkout -b feature/amazing-feature `
170+ 3 . ** Make your changes**
171+ 4 . ** Commit your changes** : ` git commit -m 'Add amazing feature' `
172+ 5 . ** Push to the branch** : ` git push origin feature/amazing-feature `
173+ 6 . ** Open a Pull Request**
174+
175+ ### Contribution Guidelines
176+
177+ - Follow the existing code style
178+ - Add tests for new functionality
179+ - Update documentation for changes
180+ - Ensure all tests pass
181+ - Be respectful and constructive in discussions
182+
183+ ### Getting Help
184+
185+ - 📖 Read our [ Contributing Guide] ( CONTRIBUTING.md )
186+ - 💬 Join the [ Discord Community] ( https://aka.ms/playwright/discord )
187+ - 🐛 Report issues on [ GitHub Issues] ( https://github.com/microsoft/playwright-python/issues )
188+
189+ ---
50190
51- More comfortable in another programming language? [ Playwright] ( https://playwright.dev ) is also available in
52- - [ Node.js (JavaScript / TypeScript)] ( https://playwright.dev/docs/intro ) ,
53- - [ .NET] ( https://playwright.dev/dotnet/docs/intro ) ,
54- - [ Java] ( https://playwright.dev/java/docs/intro ) .
191+ ** Happy testing!** 🎭
0 commit comments