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