Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method: get_select_options() to create a list from the text of "select" "option" elements #1460

Closed
anilreddy opened this issue Aug 17, 2022 · 2 comments · Fixed by #1463
Assignees
Labels
enhancement Making things better SeleniumBase 4 SeleniumBase 4 workaround exists You can reach your destination if you do this...

Comments

@anilreddy
Copy link

anilreddy commented Aug 17, 2022

If we need to assert text values in the select list there are no function in the API in seleniumbase.
Can you please add self.get_option and self.get_options to get the text values in select list so that it will be useful for asserting text values of options

@mdmintz
Copy link
Member

mdmintz commented Aug 17, 2022

What you're looking for is something like:

[e.text for e in self.find_elements("select option")]

which is already a single line of code.

I could add a method for that to make it easier to do.
It will probably end up looking like this once implemented:

self.get_select_options(
    dropdown_selector, attribute="text", by="css selector", timeout=None
)

@mdmintz mdmintz changed the title need to add a method to get_option and get_options for select list Add method: get_select_options() to create a list from the text of "select" "option" elements Aug 17, 2022
@mdmintz mdmintz self-assigned this Aug 17, 2022
@mdmintz mdmintz added enhancement Making things better workaround exists You can reach your destination if you do this... labels Aug 17, 2022
@mdmintz
Copy link
Member

mdmintz commented Aug 17, 2022

The longer version with details:

def get_select_options(
        self,
        dropdown_selector,
        attribute="text",
        by="css selector",
        timeout=None,
    ):
        """Returns a list of select options as attribute text (configurable).
        @Params
        dropdown_selector - The selector of the "select" element.
        attribute - Choose from "text", "index", "value", or None (elements).
        by - The "by" of the "select" selector to use. Default: "css selector".
        timeout - Time to wait for "select". If None: settings.SMALL_TIMEOUT.
        """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Making things better SeleniumBase 4 SeleniumBase 4 workaround exists You can reach your destination if you do this...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants