automation
==Splinter is an abstraction of Selenium, and a more advanced use of ==
Splinter
About the Splinter && Selenium blog
Ourselves automatically simulates browser clicks
Related articles by PalyWright
Playwright document
The ourselves may be ourselves down the drain. The ourselves may be ourselves down the drain. The ourselves may be ourselves down the drain -m CodeGen -o: Saves the recorded script to a file. Target: specifies the language in which the script is generated, either JS or Python. The default is python-b: specifies the browser driverCopy the code
playwright demo
python -m playwright codegen –target python -o ‘my.py’ -b chromium www.baidu.com
Synchronously open three browsers in turn, search at Baidu, and exit after taking screenshots.
from playwright import sync_playwright
with sync_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = browser_type.launch()
page = browser.newPage()
page.goto('https://baidu.com/')
page.screenshot(path=f'example-{browser_type.name}.png')
browser.close()
Copy the code
Asynchronous Asynchronous operations can be combined with asyncio to perform three browser operations simultaneously.
import asyncio
from playwright import async_playwright
async def main():
async with async_playwright() as p:
for browser_type in [p.chromium, p.firefox, p.webkit]:
browser = await browser_type.launch()
page = await browser.newPage()
await page.goto('http://baidu.com/')
await page.screenshot(path=f'example-{browser_type.name}.png')
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
Copy the code
Even better on mobile, the offender can also support mobile browser emulation. Here’s a snippet of code from the official document that simulates Safari on the iPhone 11 Pro in a given geographic location, first navigating to maps.google.com, then performing the location and taking a screenshot.
from playwright import sync_playwright
with sync_playwright() as p:
iphone_11 = p.devices['iPhone 11 Pro']
browser = p.webkit.launch(headless=False)
context = browser.newContext(
**iphone_11,
locale='en-US',
geolocation={ 'longitude': 12.492507, 'latitude': 41.889938 },
permissions=['geolocation']
)
page = context.newPage()
page.goto('https://maps.google.com')
page.click('text="Your location"')
page.screenshot(path='colosseum-iphone.png')
browser.close()
Copy the code