我的列表返回错误数量的元素的原因可能是什么-不是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] 删除。
我来说两句