selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🚀 Feature]: default locator type in find_element()

Open neurocker opened this issue 4 years ago • 3 comments

Feature and motivation

I'm always working with css locators only, and I'm tired of inserting this parameter all the time in latest versions of Selenium. Maybe it will be good to add some default option?

Usage example

So instead of using by=By.CSS_SELECTOR every time:

driver.find_elements(By.CSS_SELECTOR, 'div.maschineListItemInner > a')
driver.find_elements(By.CSS_SELECTOR, 'li.usedSingleItem')
ad_element.find_element(By.CSS_SELECTOR, 'a')
ad_element.find_element(By.CSS_SELECTOR, 'a > div.usedSingleContent > div.usedPrice')

make it something like this:

options.default_locator = By.CSS_LOCATOR
...
driver.find_elements('div.maschineListItemInner > a')
driver.find_elements('li.usedSingleItem')
ad_element.find_element('a')
ad_element.find_element('a > div.usedSingleContent > div.usedPrice')

neurocker avatar Aug 12 '22 17:08 neurocker

@neurocker, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] avatar Aug 12 '22 17:08 github-actions[bot]

Selenium tries very hard to be unopinionated about the choices made by the end user, which means requiring explicit arguments instead of providing defaults in many cases.

We encourage users to create wrapper objects for elements, or at least wrapper methods for these locators that will allow making custom code within a specific project easier to read/write/use.

titusfortner avatar Aug 12 '22 19:08 titusfortner

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Sep 12 '22 00:09 github-actions[bot]