-1

I cannot click on a specific option thrown by a dropdown menu:

enter image description here

Customer group has this:

<div class="admin__action-group-wrap admin__action-multiselect-wrap action-select-wrap _active" data-role="wrap-ui-group" tabindex="0" data-bind="
        attr: {
            id: uid,
            name: inputName
        },
        css: {
            _active: listVisible,
            _disabled: disabled,
            _focus: hasFocus,
            _multiple: multiple
        },
        event: {
            keydown: keydownSwitcher,
            focusin: onFocusIn,
            focusout: onFocusOut
        },
        outerClick: outerClick.bind($data)
" id="PR1R77P" name="settings[customer_group_id]">
    <div class="admin__action-multiselect action-select" data-action="open-search" data-bind="click: toggleListVisible">
        <!--ko ifnot: multiple-->
            <div class="admin__action-multiselect-text" data-role="selected-option" data-bind="text: resultLabel">Teleweb</div>
        <!-- /ko-->
        <!--ko if: multiple--><!-- /ko -->
    </div>
    <div class="admin__action-group-list action-select-list action-menu _active" data-bind="css: { _active: listVisible }">
        <div class="admin__action-multiselect-search-wrap">
            <input class="admin__control-text admin__action-multiselect-search" data-bind="
                    hasFocus: searchFocus,
                    event: {
                        keyup: filterOptionsKeydown
                    },
                    valueUpdate: 'afterkeydown',
                    value: filterInputValue" type="text">
            <label class="admin__action-multiselect-search-label" data-action="advanced-select-search" data-bind="attr: {for: uid}, visible: !isSearchActive()
            " for="PR1R77P"></label>
            <label class="admin__action-multiselect-remove-label" data-action="advanced-select-search" data-bind="click: clearSearch, visible: isSearchActive
            " style="display: none;"></label>
            <div class="admin__action-multiselect-search-count" data-bind="visible: quantitySearchItems
                ">
                <!--ko ifnot: multiple-->
                    <span data-bind="text: quantitySearchItems">17</span>
                    <span data-bind="i18n: 'options'">options</span>
                <!-- /ko-->
                <!--ko if: multiple--><!-- /ko-->
            </div>
        </div>
        <!--ko if: group-->
            <!--ko repeat: { foreach: convertedOptions, item: 'optgroup'}--><ul class="admin__action-multiselect-menu-inner _root" data-repeat-index="0">
                <li class="admin__action-group-optgroup">
                    <strong data-bind="text: optgroup().label">Customer Groups</strong>
                </li>
                <!-- ko repeat: { foreach: optgroup().value, item: 'option'}  --><li data-role="option" class="admin__action-group-option" tabindex="-1" data-bind="
                        click: setSelected.bind($context.$data, option().value),
                        event: {
                            hover: resetHover
                        },
                        attr: {
                            'data-value': option().value
                        }" data-repeat-index="0" data-value="11">
                        <div class="action-menu-item _with-checkbox" data-bind="
                                        css: {
                                            _selected: isSelected(option().value)
                                        },
                                        clickBubble: false
                                ">
                            <!--ko if: multiple--><!-- /ko-->
                            <label class="admin__action-multiselect-label">
                                <span data-bind="text: option().label">E.BOSCH</span>
                            </label>
                        </div>
                    </li><li data-role="option" class="admin__action-group-option" tabindex="-1" data-bind="
                        click: setSelected.bind($context.$data, option().value),
                        event: {
                            hover: resetHover
                        },
                        attr: {
                            'data-value': option().value
                        }" data-repeat-index="1" data-value="8">
                        <div class="action-menu-item _with-checkbox" data-bind="
                                        css: {
                                            _selected: isSelected(option().value)
                                        },
                                        clickBubble: false
                                ">
                            <!--ko if: multiple--><!-- /ko-->
                            <label class="admin__action-multiselect-label">
                                <span data-bind="text: option().label">E.BOSCH2</span>
                            </label>
                        </div>
                    </li><!-- /ko -->
            </ul><!--/ko-->
        <!-- /ko-->
        <!--ko ifnot: group--><!-- /ko-->
        <!--ko if: multiple--><!-- /ko -->
    </div>
</div>

I can click the button by doing this:

driver.findElement(By.name("settings[customer_group_id]")).click();

I tried to click a specific option using this:

driver.findElement(By.xpath("//li[@class='admin__action-group-optgroup' and contains(.,'E.BOSCH')]")).click();

but it does not do anything at all.

What am i doing wrong? Why i cannot click on the desired option?.

Note: i cannot post the URL because it is hidden

6
  • Without actual link we can't help, I'm sorry. Commented Dec 14, 2022 at 15:31
  • Hey @Prophet do you see anything wrong in my code? Based on what is presented.. what would you do? Commented Dec 14, 2022 at 15:36
  • I don't know. There are several possible things that may make this not working Commented Dec 14, 2022 at 15:38
  • 1
    If you use sleep before clicking the option? Maybe your problem is that the element is not still present. Also, try this driver.findElement(By.xpath("//span[@data-bind='text: option().label' and text()='E.BOSCH2']")).click(); instead of driver.findElement(By.xpath("//li[@class='admin__action-group-optgroup' and contains(.,'E.BOSCH')]")).click(); Commented Dec 14, 2022 at 16:00
  • @JakyRuby Thank you!!, it worked for me. But please.. could you explain to me and "us" why my method did not worked?. You rock! Commented Dec 14, 2022 at 16:09

1 Answer 1

1

Use

driver.findElement(By.xpath("//span[@data-bind='text: option().label' and text()='E.BOSCH2']")).click();

instead of

driver.findElement(By.xpath("//li[@class='admin__action-group-optgroup' and contains(.,'E.BOSCH')]")).click();

Problem is that your xpath did not work because the elemnt that contains the text E.BOSCH is not an li, actually is an span.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey pal, could you please take a look at this?: stackoverflow.com/questions/74816164/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.