1

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"])

3
  • 1
    Where are you stuck exactly? Update the question with the error stack trace Commented May 4, 2018 at 8:16
  • relevant HTML and error trace ? Commented May 4, 2018 at 8:17
  • org.openqa.selenium.support.ui.ExpectedConditions findElement WARNING: WebDriverException thrown by findElement(By.xpath: //*[@id="AMEX-paymenttype"]) Commented May 4, 2018 at 8:48

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

3 Comments

WebDriverException thrown by findElement(By.xpath: //*[@id=\"AMEX-paymenttype\"]) org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot find context with specified id"} (Session info: chrome=66.0.3359.139) I am using TestNG. weird it is working on a Java class but not on TESTNG Class.
unhandled inspector error indicates the xpath you have identified as //*[@id=\"AMEX-paymenttype\"] is incorrect. Either you use a correct xpath or provide the relevant HTML
when I run my class as java application the element is clickable, but in TestNG I encountered this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.