yashaka / selene

User-oriented Web UI browser tests in Python
https://yashaka.github.io/selene/
MIT License
691 stars 150 forks source link

should we help users do not shoot their legs when using browser.all(selector) in for loops? #534

Open yashaka opened 4 months ago

yashaka commented 4 months ago

This code may not do what the end user wants...

from selene import browser
from my_project.helpers.data import random_number

...

for code in browser.all('.code'):
    code.set_value(random_number())

One would think that it will go through all, for example 3 available fields on screen... But in fact, if fields are dynamically loaded, the for loop may just not wait for all 3 element to appear before looping through them...

That's why, actually you need something like this:

from selene import browser
from my_project.helpers.data import random_number

...

for code in browser.all('.code').should(have.size(3)):
    code.set_value(random_number())

Question, should we make it a bit more straightfoward/obvious to use? maybe something like this (by making collection iterator waitable...):

from selene import browser
from my_project.helpers.data import random_number

...

for code in browser.all('.code')[:3]:
    code.set_value(random_number())