簡體   English   中英

如何使用findElements選中dropdownmenu中的復選框並獲取? (爪哇/ seleniumWebDriver)

[英]how to check checkbox in dropdownmenu using findElements and get ? (java/seleniumWebDriver)

我有: 在此處輸入圖片說明

List<WebElement> checkboxes = driver.findElements(By.xpath("//ul[@class='dropdown-menu js-dropdown-menu dropdown-menu-form']/li/div/label/span/span[@class='check']"));
    checkboxes.get(1).click();

Xpath 為什么get不工作?

那就是因為您要在//ul[@class='dropdown-menu js-dropdown-menu dropdown-menu-form']/li/div/label/span/span[@class='check']中查找所有包含類'check'的元素//ul[@class='dropdown-menu js-dropdown-menu dropdown-menu-form']/li/div/label/span/span[@class='check'] ,只有一個元素。 另外,您是否需要使用List? 我的意思是,您可以按如下所示直接單擊它:如果您想單擊“ Do ustalenia”,

driver.findElement(By.xpath("//ul[@class='dropdown-menu js-dropdown-menu dropdown-menu-form']/li/div/label/span/span[@class='check']")).click();

或者您可以共享更多HTML復選框。 我對此猜測:

List<WebElement> checkboxes = driver.findElements(By.xpath("//span/span[@class='check']")); // this will find all span elements with class 'check' inside li/div/label
checkboxes.get(1).click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM