我需要勾选“添加 GPU”复选框。网站 https://cloud.google.com/products/calculator 有代码
WebElement checkAddGRU = new WebDriverWait(driver, 20)
.until(ExpectedConditions.
presenceOfElementLocated(By.xpath("//md-input-container/md-checkbox/div[contains(text(),'Add GPUs')]")));
WebElement numberOfGPU = new WebDriverWait(driver, 10)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//md-select[@placeholder='Number of GPUs']")));
while (!numberOfGPU.isDisplayed()) {
checkAddGRU.click();
}
但是这不起作用。该复选框至少为空。
最佳答案
您无法选择该复选框的原因是 iframe 中存在该复选框。尝试先切换到 iframe,然后选中该复选框。
WebElement iframe = driver.findElement(By.cssSelector("#myFrame"));
driver.switchTo().frame(iframe);
driver.findElement(By.xpath("//md-input-container/md-checkbox/div[contains(text(),'Add GPUs')]").click()
关于java - 需要在WebDriver中选中一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60637415/