1

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();
Phil
  • 339
  • 2
  • 13
  • you have multiple problems currently, what error do you get? – Sergey Pleshakov Apr 28 '21 at 19:18
  • While running the test script, I visually observe the selection in dropdown box, but it does not choose different value. for instance if my dropdown box selects bank account so i want to choose credit card instead, but it does not do anything so the selection remains as bank account. – Phil Apr 28 '21 at 20:29

1 Answers1

1

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

Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
  • 1
    thanks, the code is working. it was my mistake because I kept choosing the same selection. – Phil Apr 28 '21 at 22:14