首页 > 解决方案 > 我无法使用 selenium webdriver 在下拉列表中选择复选框

问题描述

看起来像这样 id("ctl05_cbMulti_DropDown")/div[@class="rcbScroll rcbWidth"]/ul[@class="rcbList"]/li[@class="rcbHovered"]/label[1]/input[@类="rcbCheckBox"]

这些都不起作用

司机。findElement(By.xpath("(//input[@type='checkbox'])[2]")).click(); 或 driver.findElement(By.id("ctl05_ctl03_cblUser_Input")).sendKeys("Smith, John");

标签: javaselenium

解决方案


我在您的第一行代码中看到了一些错误。您不应该在 xpath 中传递“(”。

正确的代码应该是:

new WebDriverWait(driver, 30).until(ExpectedConditions.ElementToBeClickable (By.xpath("//input[@type='checkbox'][2]")));

driver. findElement(By.xpath("//input[@type='checkbox'][2]").click();

推荐阅读