我正在尝试选择一个复选框,但我无法选择,也没有在其他线程中找到任何解决方案。
代码: @FindBy(css="input.ng-valid.ng-dirty.ng-touched") WebElement chrgAllocFee;
chrgAllocFee.click();
但是当我以相同的方式定义和使用时,它无法像其他复选框一样工作。我发现与其他代码相比,不同之处在于这里的 html 代码有额外的行
请建议如何定义以便可以识别。
获取错误: org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:{“method”:“css选择器”,“selector”:“input.ng-valid.ng-dirty.ng-touched”} ( session 信息:chrome=69.0.3497.92)
最佳答案
所需的元素是 Angular元素,因此您必须引发 WebDriverWait 才能使 元素可点击,并且您可以使用以下解决方案之一:
css选择器
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.ng-valid.ng-dirty.ng-touched[name='ChargeAllocationFee']"))).click();
xpath
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='ng-valid ng-dirty ng-touched' and @name='ChargeAllocationFee']"))).click();
关于java - 无法使用 java 选择 Selenium Webdriver 中的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52601291/