Reputation: 27
I want to click an element inside a iframe
code trial :
driver.switchTo().frame("payment_page");
WebElement cardType = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"AMEX-paymenttype\"]")));
cardType.click();
Error Msg: org.openqa.selenium.support.ui.ExpectedConditions findElement WARNING: WebDriverException thrown by findElement(By.xpath: //*[@id="AMEX-paymenttype"])
Upvotes: 1
Views: 1577
Reputation: 193058
As per the Best Practices before you switch to any frame you need to induce WebDriverWait for the frame to be available and switch to it. Once you have switched to the desired frame further as you are invoking click()
method so instead of using the ExpectedConditions method visibilityOfElementLocated you need to use elementToBeClickable
as follows :
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("payment_page")));
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"AMEX-paymenttype\"]"))).click();
Upvotes: 1