我想点击iframe
代码试用:
driver.switchTo().frame("payment_page");
WebElement cardType = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"AMEX-paymenttype\"]")));
cardType.click();
错误消息: org.openqa.selenium.support.ui.ExpectedConditions findElement警告:findElement抛出WebDriverException(By.xpath:// * [@ id =" AMEX-paymenttype"])
答案 0 :(得分:1)
根据最佳做法切换到任何框架之前,您需要为框架引导 WebDriverWait 可用并切换到它。在调用click()
方法后进一步切换到所需的框架,而不是使用 ExpectedConditions 方法 visibilityOfElementLocated 使用elementToBeClickable
如下:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("payment_page")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"AMEX-paymenttype\"]"))).click();