1

enter image description here

Below is the html code:

<li>
  <a id="inputBox" class="menulink menuhover">Scotia Mortgage</a>
  <ul id="listOptions" style="overflow: visible; display: block; height:     148px; z-index: 414; visibility: visible; opacity: 1;">
    <li>
      <li>
        <a class="sub ">Credit Card</a>
        <ul style="overflow: hidden; display: block; height: 0px; z-index: 415; opacity: 0.0153846;">
          <li class="topline">
            <a class="sub">American Express</a>
            <ul style="overflow: hidden; display: block; height: 0px; z-index: 401; opacity: 0.0153846;">
              <li class="topline">
                <a onclick="changeValue(this, 'AmExRegular')">Scotiabank American Express Card</a>
               </li>
               <li>
                 <a onclick="changeValue(this, 'AmExGold')">Scotiabank Gold American Express Card</a>
               </li>
               <li class="bottomline">
                 <a onclick="changeValue(this, 'AmExPlatinum')">Scotiabank Platinum Amex Card</a>
               </li>
             </ul>
           </li>
           <li>
             <a class="sub ">Master Card</a>
             <ul style="overflow: hidden; display: block; height: 0px; z-index: 397; opacity: 0.0434783;">
               <li class="topbottomline">
                 <a onclick="changeValue(this, 'ScotiaMasterCard')">Scotia Momentum MasterCard</a>
               </li>
             </ul>
           </li>
           <li class="bottomline">
             <a class="sub ">VISA</a>
             <ul style="overflow: hidden; display: block; height: 0px; z-index: 398; opacity: 0.00671141;">
           </li>
         </ul>
       </li>
       <li>
         <a class="sub ">Line of Credit</a>
         <ul style="overflow: hidden; display: block; height: 0px; z-index: 417; opacity: 0.0116279;">
       </li>
       <li>
         <a onclick="changeValue(this, 'OverdraftProtection')">Overdraft Protection</a>
       </li>
       <li>
         <a id="mortgageItem" onclick="changeValue(this, 'Mortgage')">Scotia Mortgage</a>
       </li>
       <li>
         <a onclick="changeValue(this, 'ScotiaPlanLoan')">Scotia Plan Loan</a>
       </li>
       <li class="bottomline">
         <a onclick="changeValue(this, 'TotalEquityPlanService')">Scotia Total Equity Plan</a>
       </li>
     </ul>
   </li>

While selecting "Credit Card" I used xpath as .//*[@id='listOptions']/li[2]/a and then under Credit Card I have selected "American Express" by using xpath as ".//*[@id='listOptions']/li[2]/ul/li[1]/a". Both are working fine.

But while selecting "Scotiabank American Express Card" I have used xpath as ".//*[@id='listOptions']/li[2]/ul/li[1]/ul/li[1]/a", this one is not working and got this below message,

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with 
Command duration or timeout: 15 milliseconds PFA
  • Try to reformulate your question and give us some evidence you have put ypur effrot to solve your problem. – Alexey R. Oct 30 '17 at 11:22
  • What will be the locator for "Scotiabank American Express Card"? – Raj Oct 30 '17 at 11:30
  • It looks like your final selection ("Scotiabank American Express Card") doesn't load until you've selected "American Express". You probably need something like the solutions in the answers to sqa.stackexchange.com/questions/1299/selenium-ajax-testing – Kate Paulk Oct 30 '17 at 11:59
  • 2
    I am not sure what is our policy about the questions which display lack of elementary skills. Are we here to teach basics of coding and debugging, which student will get during first few weeks of training? Because such trivial questions are just a noise for most of the more skilled users (say 1 year of experience), so as a result most visitor will form the opinion that questions asked here are to basic and trivial to be worth subscribing to this forum and grow the community. – Peter M. - stands for Monica Oct 30 '17 at 15:56
  • yeaahh .. u r correct @Kate.. – Raj Oct 31 '17 at 6:29
0

Hey please try with this locator

By.cssSelectore(#listOptions li ul li li:nth-child(1))

Also, try to use CSS selectors as it is more effective and accurate as compared to xpath.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.