Developer Snippet Diary

Forms and Actions (interact with HTML Input elements)

FORMS and actions:  https://playwright.dev/python/docs/input

Fill input boxes

page.get_by_role("textbox").fill("Peter") # Text input
page.get_by_label("Birth date").fill("2020-02-02") # Date input
page.get_by_label("Appointment time").fill("13:15") # Time input
page.get_by_label("Local time").fill("2020-03-02T05:15") # Local datetime input
page.get_by_label('I agree to the terms above').check() #checkbox
page.get_by_label('Choose a color').select_option('blue') # select 
page.get_by_role("button").click() # Generic click
page.locator('#area').press_sequentially('Hello World!') # Press keys one by one
page.get_by_label('password').focus() #focus element

 Press Keys:  
 page.get_by_text("Submit").press("Enter") #press enter
 https://playwright.dev/python/docs/input#keys-and-shortcuts

 Upload files:
 https://playwright.dev/python/docs/input#upload-files

 Drag and drop:

https://playwright.dev/python/docs/input#drag-and-drop

 Scrolling:

 https://playwright.dev/python/docs/input#scrolling

 # Scroll the footer into view, forcing an "infinite list" to load more content
 page.get_by_text("Footer text").scroll_into_view_if_needed()


 Position the mouse and scroll with the mouse wheel

 page.get_by_test_id("scrolling-container").hover()
 page.mouse.wheel(0, 10)
Posted by: R GONDAL
Email: rizikmw@gmail.com