我需要自動化一個方案 - 我需要點擊展開所有按鈕&檢查所有過濾器是否展開,然後單擊摺疊所有按鈕並檢查是否所有過濾器都已摺疊。Selenium Java-Checking存在/不存在Weblist元素
我使用的方法是把所有的過濾器放入一個weblist中,得到它的大小&然後使用assert方法檢查它是否非空,但是用於檢查崩潰功能,這種方法是失敗的。
有沒有一種方法來檢查的webelements名單就像我們已經isDisplayed()單個webelement知名度或存在?
下面是上述邏輯,我試圖代碼:
driver.findElement(By.linkText("Expand All")).click();
Thread.sleep(3000);
System.out.println("Clicking on the Expand All option");
Assert.assertFalse(driver.findElements(By.cssSelector("input[type='checkbox']")).isEmpty(),"The Filters are not expanded");
int filters_max_size=driver.findElements(By.cssSelector("input[type='checkbox']")).size();
System.out.println("There are total "+filters_max_size+ "filters expanded");
System.out.println("Clicking on the Collapse All option");
Reporter.log("Clicking on the Collapse All option");
driver.findElement(By.id("collapse_all")).click();
Thread.sleep(3000);
Assert.assertTrue(driver.findElements(By.cssSelector("input[type='checkbox']")).isEmpty(),"The Filters are not collapsed");
Assert.assertEquals(0, driver.findElements(By.cssSelector("input[type='checkbox']")).,"The Filters are not collapsed");
<a class="refinement_anchor" href="/search?button=search&expand_all=5B%5D=%7B%22s%22%3A%5B%7B%22id%22%3A%22%22%2C%22xPath%22%3A%22%24source_type%22%2C%22logic%22%3A%22OR%22%2C&utf8=%E2%9C%93">
<input id="refinement_214391870" class="flex" type="checkbox" name="refinement_214391870">
<label class="text" for="refinement_214391870">
<div class="text refinement_information">
<span class="label" data-token="{"s":[{"id":"refine_source_type","xPath":"$source_type","logic":"OR","s":[{"n":"Selective"}]}]}" title="Selective"> Selective </span>
<span class="ndocs"> (136,292) </span>
</div>
</label>
</a>
</li>
<li class="text no_children ">
</ul>
<a class="show_all" href="/search/show_all?button=search&id=&q=&types=&utf8=%E2%9C%93&widget_id=refine_source_type">Show all</a>
</div>
什麼是後collapsing.can你得到ü嘗試一下崩潰 – SaiPawan
大小爲86,同時擴大和崩潰 –
是,這意味着它們仍然會附加到dom.you它仍然是相同的後印刷尺寸大小可檢查isclickable()每個element.Have你試圖isDisplayed() – SaiPawan