2017-04-20 69 views
-1

我需要在每3秒钟后从这里一个一个地选择所有复选框。我试着夫妇的XPath与名单,他们都没有工作如何在硒中选择复选框中的复选框one-by-one?

divs

试过的XPath:

  1. //div/div[@class='filters-list sdCheckbox ']
  2. 使用输入和类型。但他们都没有工作。你能帮我解决吗?

    参考网站:https://www.snapdeal.com/products/storage-devices?sort=plrty - 在左上角

  3. By.xpath("//a[@class='filter-name']")这一个罗列出来页的所有滤镜>能力。

+0

尝试通过包含的文本选择复选框。你的情况会更轻松。编写一个带有复选框标签文本的函数,例如8GB或其他,并选择基于此的复选框。 – JeffC

+0

我需要在每3秒钟一个一个地逐个选择所有人。所以不能用列表 – Ritu

+0

来完成。请说明你的情况并提供详细信息。该页面上有很多复选框。你想要点击哪些?您是否打算单击一个选择它,然后再次单击它以取消选择它,然后单击下一个,或者是否打算在最后检查所有框? – JeffC

回答

0

xPath "//div[@data-name='Capacity_s']/div[@class='filters-list sdCheckbox ']/input"将为您提供您需要检查的所有输入元素的列表。

0

存在一个容器DIV,其容纳特定类型的所有过滤器,例如,品牌,容量等品牌的品牌如下所示。

<div class="filter-inner " data-name="Brand"> 

在该容器中,所有的标签标签是你所需要单击以选中复选框。所以,我们可以使用分组来创建一个CSS选择器作为过滤器,以便只访问我们想要的复选框。

"div[data-name='Brand'] label" 

由于这是我认为你会重用,我会写这个函数。

public static void CheckFilters(String filterGroup) 
{ 
    WebDriverWait wait = new WebDriverWait(driver, 10); 
    List<WebElement> filters = driver.findElements(By.cssSelector("div[data-name='" + filterGroup + "'] label")); 
    // System.out.println(filters.size()); // for debugging 
    for (int i = 0; i < filters.size(); i++) 
    { 
     filters.get(i).click(); 

     // wait for the two overlays to disappear 
     wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.searcharea-overlay"))); 
     wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("div.filterLoader.hidden"))); 

     // reload the element list after the refresh so you don't get StaleElementExceptions 
     filters = driver.findElements(By.cssSelector("div[data-name='" + filterGroup + "'] label")); 
    } 
} 

,你会这样称呼它

driver.get("https://www.snapdeal.com/products/storage-devices?sort=plrty"); 
CheckFilters("Brand"); 
+0

这是一个很大的帮助..感谢一吨 – Ritu