question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Add possibility of creating Locators with variables

See original GitHub issue

Hi, it would be more convenient to create Locators with the possibility of specifying variable values exactly before executing some actions. For example I have two elements on the page:

await this.page.click('.header-actions [helptag="default-filters"]:not(.mat-button-disabled)');
await this.page.click('.header-actions [helptag="apply-filters"]:not(.mat-button-disabled)');

As we can see, only helptag differs. With the current implementation of Locators I need to create 2 locator elements or make my own functions to generate raw string selector and pass it to locator. I propose creating out-of-the box implementation in Locators for such functionality. Maybe something like this:

headerActionBtns = this.page.locator('.header-actions [helptag="${btnName}"]:not(.mat-button-disabled)', btnName)
headerActionBtns.click({btnName: 'default-filters'});
or
headerActionBtns.with({btnName: 'default-filters'}).click(); 

Please consider. Thank you

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielStoica85commented, Aug 8, 2022

+1 for this. I ran into many situation where multiple locators are pretty much the same, except for their text. So it would be great to use the same locator for all those elements and just have a variable for the text value.

0reactions
andersoncorbellinicommented, Oct 17, 2022

+1, this feature will be awesome for the community.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Locators In Selenium WebDriver With Examples - LambdaTest
This blog deep dives into the multiple locators in Selenium WebDriver and demonstrates the usage of those locators while performing Selenium ...
Read more >
How to pass a variable to the selector and the python function ...
In the locators file, I write my selector, which contains a variable. I need it to be variable because later on I will...
Read more >
Locators and Variables
Variables represent text strings to be replaced at the time of the execution of a test case. We have predefined variables ready to...
Read more >
How to use locators with parameters
use a locator for each page element; use a method that creates the locator for each page locator; use a locator pattern with...
Read more >
Page Object Model (POM) In Selenium With Examples || Toolsqa
Additionally, if there is a change in such a locator, you will have to go through the entire code to make the necessary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found