列表<WebElement>返回错误的元素数量

亚历克斯·亚历克斯

我的列表返回错误数量的元素的原因可能是什么-不是9,而是13?因此,我无法验证这些项目-实际9之前似乎有4个元素。任何建议将不胜感激。

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);
            }

判断

<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>

输出量

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
约拿

确保您的CSS选择器By.cssSelector("div.logoSelect > ul li.logoSelectOpt")仅找到所需的元素。使其更窄,您的代码将正常工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

List<WebElement> 返回空列表

陈旧元素:遍历 webelement 列表 python

返回具有相同元素数量的列表

调用WebElement列表的个人索引

WebElement列表中的相对Xpath

无法在列表中的列表中单击 WebElement

如何获取列表中的元素数量?

列表中的Python元素数量

使用 Pything 访问 Selenium 中的 webelement 列表中的 webelement

在列表列表中查找元素数量最多的列表

元素不能位于(x,y):如何修复需要逐一单击的WebElement列表

如何覆盖 findElements 方法,以便它返回实现 WebElement 接口的类型列表

谷歌地图错误列表索引必须是整数或切片,而不是 WebElement

如何返回列表中出现的元素数?

查找列表中大于其相邻元素的元素数量

{WebElement} .getAttribute( “值”)返回0

硒:将WebElement添加到列表中,然后检查所有元素的可见性

通過使用 for 循環迭代每個元素,將 Webelement 文本添加到列表中

以R中的元素数量为条件的删除列表

如何限制python列表中的元素数量

如何填充元素数量由变量决定的元组列表

如何在 Python 中获取列表中的元素数量?

从集合列表中查找元素数量最少的集合

如何限制可放置列表中的元素数量?

为什么初始化列表中的元素数量会导致模棱两可的调用错误?

如何根据内部列表中的元素数量排序列表列表?-蟒蛇

根据列表列表中的元素数量制作不同的列表

计算矩阵列表中的元素数,并根据条件返回

Selenium WebDriver- WebElement.FindElements返回比预期更多的元素