Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how to deal with filling a dropdown with a specifc optgroup? #3886

Answered by mdmintz
ulfgj asked this question in Q&A
Discussion options

unfortunately in each optgrgoup we have options with the same values...

in the collect/read script

icon_dropdown = 'div.field--name-field-oe-icon select'
icon_text = sb.get_text(f'{icon_dropdown} option[selected]')
icon_value = sb.get_attribute(f'{icon_dropdown} option[selected]', 'value')
dropdown_element = sb.find_element(f'{icon_dropdown} option[selected]')
optgroup_element = dropdown_element.find_element("xpath", "ancestor::optgroup") # parent of selected option
optgroup_label = optgroup_element.get_attribute("label")

in the fill/create-script

icon_dropdown = 'div.field--name-field-oe-icon select'
sb.select_option_by_value(f'{icon_dropdown} optgroup[label="{data["optgroup_label"]}"] option', data['icon_value'])

the last line throws the error:
UnexpectedTagNameException(f"Select only works on <select> elements, not on {webelement.tag_name}")

how do we select an option with a specificed optgroup?

You must be logged in to vote

The select_option_by_* methods only work on <select> elements with <option> tags.

You can probably use js_click(selector) to click what you want, even if the option is hidden.

Replies: 2 comments

Comment options

The select_option_by_* methods only work on <select> elements with <option> tags.

You can probably use js_click(selector) to click what you want, even if the option is hidden.

You must be logged in to vote
0 replies
Answer selected by mdmintz
Comment options

thnx michael! js_click didn't work somehow, though.
messed aroun dand found that a normal click with xpath worked:
sb.click(f"//optgroup[@label='{label}']/option[@value='{icon}']")

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /