Description
🚀 Feature Request
it would be nice if playwright allowed you to pass a datetime.timedelta
object to functions that take timeouts, as it more clearly describes the unit of time being used.
Example
from datetime import timedelta
page.click("div", timeout=timedelta(minutes=5))
Motivation
preventing mistakes
currently, it's easy to accidentally misuse the timeout
argument for example if the user incorrectly assumes it refers to seconds instead of milliseconds:
from time import sleep
time.sleep(5) # waits 5 seconds
page.wait_for_timeout(5) # waits 5 milliseconds
(yes i know you should never use time.sleep
with playwright. this example is just to illustrate that there are builtin functions that take seconds instead of milliseconds, which makes it more likely that a user could incorrectly assume that playwright does the same)
improving readability
it can also make code that waits for longer amounts of time look cleaner. currently you're forced to either write the literal number of milliseconds which is often difficult to read, or split it up into factors representing each unit:
page.click("div", timeout=300000)
page.click("div", timeout=5 * 60 * 1000)
both of these are less reradable than using a timedelta
:
page.click("div", timeout=timedelta(minutes=5))