I want to find the input element in the iframe, however selenium is not able to locate it.
I used both switchTo().frame(id)
and switchTo().frame(index)
, but none of it works.
Here is my code:
driver.switchTo().defaultContent();
WebElement ele = driver.findElement(By.xpath("//iframe[contains(id, 'braintree-hosted-field-number')]"));
driver.switchTo().frame(ele);
Error Message:
no such element: Unable to locate element: {"method":"xpath","selector":"//iframe[contains(id, 'braintree-hosted-field-number')]"} (Session info: chrome=76.0.3809.132)
Screenshot: