You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Selector is an implementation detail of the locator, we can't create locator from selector in the general case. But we can try amending conditions like you attribute. I'll close this one in favor of withAttribute. We already have text and exact text matching via adding .locator('text=Hello').
Pavel Feldman (@pavelfeldman) if you are implementing only withAttribute() then i need to open new feature requests for withText() and withExactText() (or withText with regexp support).
This is because withAttribute() and your suggested .locator('text=Hello') does not solve my problem entirely :)
withAttribute() already exists too, it is .locator([attribute-name="someValue"]) so in theory anyone could use this, but what we need is to be able to extend current locator instead of searching for new thing within parent locator.
const countryOptionCssSelector = 'option'
const disabledCountryOptionCssSelector = 'option'
const pageObject1 = {
$ = {
countries: this.page.locator(countryOptionCssSelector)
disabledCountries: this.page.locator(`${countryOptionCssSelector}${disabledCountryOptionCssSelector}`)
country: (name: string | Regexp) => this.page.locator(`${countryOptionCssSelector} text=${name}`)
disabledCountry: (name: string | Regexp) => this.page.locator(`${countryOptionCssSelector}${disabledCountryOptionCssSelector} text=${name}`)
}
}
# Not to mention that sometimes you are passing parentElement to nested page objects, or you need to reuse/extend selector from other page object and it gets even less nice
# It's harder to maintain code and you need to keep track where you have all of those CssSelectors defined.
import countryOptionCssSelector from ...
import disabledCountryOptionCssSelector from ...
const pageObject2 = {
$ = {
something: this.page.locator(`${countryOptionCssSelector}${disabledCountryOptionCssSelector} ...`)
}
}
Activity
pavelfeldman commentedon Nov 9, 2021
Looks like if we address #10177, you wouldn't need this one, right?
Evilweed commentedon Nov 9, 2021
Pavel Feldman (@pavelfeldman) i think it would be still useful to be able to create selectors that cannot be created with
.withAttribute()For example to create equivalents of:
withText()withExactText()Seems like
.withAttribute()is easier to use, but this seems to be more powerful:pavelfeldman commentedon Nov 10, 2021
Selector is an implementation detail of the locator, we can't create locator from selector in the general case. But we can try amending conditions like you attribute. I'll close this one in favor of withAttribute. We already have text and exact text matching via adding
.locator('text=Hello').Evilweed commentedon Nov 10, 2021
Pavel Feldman (@pavelfeldman) if you are implementing only withAttribute() then i need to open new feature requests for withText() and withExactText() (or withText with regexp support).
This is because withAttribute() and your suggested
.locator('text=Hello')does not solve my problem entirely :)withAttribute() already exists too, it is
.locator([attribute-name="someValue"])so in theory anyone could use this, but what we need is to be able to extend current locator instead of searching for new thing within parent locator.So much easier to create DRY code like that:
Than this: