Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97773

List returns wrong number of elements

$
0
0

What could be the reason why my List returns wrong number of elements - instead of 9 it finds 13? Hence, I cannot validate the items - it appears like there are 4 elements in front of the actual 9. Any advise will be appreciated.

public void staffList() throws InterruptedException{
            Actions act =  new Actions(driver);
            act.moveToElement(driver.findElement(By.id("img_add_staff"))).click().perform();
            Thread.sleep(5000);
            String[] expected = {"Administrative - Management", "Administrative - Assistance", "Dentist",   "Information Technology Staff", "Medical Student", "Nurse", "Pharmacist", "Physician", "Other"};
            List<WebElement> list = new WebDriverWait(driver,20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector("div.logoSelect > ul li.logoSelectOpt")));
            Thread.sleep(1000);
            if (expected.length != list.size()) {
                System.out.println("fail, wrong number of elements found");
            }
            System.out.println(list.size());
            for(int i=0; i<expected.length; i++){ 
            String optionValue = list.get(i).getText();
            if (optionValue.equals(expected[i])) {
                System.out.println("passed on: " + optionValue);
            } else {
                System.out.println("failed on: " + optionValue);
            }

DOM

<div class="logoSelect" sstyle="z-index: 1; top: 2264px; left: 431.5px; width: auto;">==$0
 <ul>
  <li class="logoSelectOpt" id="Amdin" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Administrative - Management</li>==0
  <li class="logoSelectOpt" id="AdAssist" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Administrative - Assistance</li>==0
  <li class="logoSelectOpt" id="Dentis" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Dentist</li>==0
  <li class="logoSelectOpt" id="INFO" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Information Technology Staff</li>==0
  <li class="logoSelectOpt" id=MedSt" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Medical Student</li>==0
  <li class="logoSelectOpt" id="Nurs" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Nurse</li>==0
  <li class="logoSelectOpt" id="Pharm" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Pharmacist</li>==0
  <li class="logoSelectOpt" id="Phys" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Physician</li>==0
  <li class="logoSelectOpt" id="Oth" onmouseover="jQuery(QWE01Title.activate(this);" onmouseout="jQuery(QWE01Title.deactivate(this);" onmousedown="jQuery(QWE01Title.selectItem(this);" logoColor="#FFF">Other</li>==0
 </ul>
</div>

Output

fail, wrong number of elements found
13

failed on: 
failed on: 
failed on: 
failed on: 
failed on: Administrative - Management
failed on: Administrative - Assistance
failed on: Dentist
failed on: Information Technology Staff
failed on: Medical Student
failed on: Nurse
failed on: Pharmacist
failed on: Physician
failed on: Other

Viewing all articles
Browse latest Browse all 97773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>