Phil
Phil

Reputation: 349

Protractor JavaScript choose value in dropdown box that has subcategory

I'm try to choose different value from the dropdown box however my dropdown box has subcategory so I'm having issue to locate the web element. for example, let's say I have the following:

dropDownBox-> Bank Account     -> account#76789
                               -> account#99222
                               -> account#55555

           -> Credit Card      -> card#1234567
                               -> card#4444499
                               -> card#4406699

HTML

<select name="ctl00$main$ddlPaymentAccounts" id="main_ddlPaymentAccounts" class="sel" onchange="javascript:checkPayAcct();" title="Select Payment Account" style="width: 220px!important">
    <option value="0">
        Select Payment Method
    </option><optgroup label="Bank Account">
        <option title="Account Holder:My Test | Bank Number:044002161 | Account Type:DA | Account Number************6789" value="OTC_260511" selected="selected">
            ChazeBank
        </option>
    </optgroup><optgroup label="Credit Card">
        <option title="Account Holder:My Test | Expiration:0430 | Account Type:VI | Account Number************4499" value="CC_838022">
            AmericanExpressCard
        </option>
    </optgroup>
</select>

I have tried to locate the element with ID and XPath, but no luck because Protractor cannot locate the web element

    var dropdownXPath = "//*[@id='main_ddlPaymentAccounts']/optgroup[2]/option[1]";
    var webElement = element(by.xpath(dropdownXPath));
    browser.wait(EC.elementToBeClickable(webElement), 60000);
    webElement.click();

Upvotes: 1

Views: 42

Answers (1)

Sergey Pleshakov
Sergey Pleshakov

Reputation: 8978

your xpath is right, so it's not a problem.

If you don't get any error thrown on this step (ie element is present and clicked), but nothing happens, then try this https://stackoverflow.com/a/66110526/9150146

Upvotes: 1

Related Questions