selenium webdriver – Getting error as no element found for iframe

Written code to locate iframe as below:

WebElement iframe = driver.findElement(By.xpath("//iframe\[@src="https://stackoverflow.com/questions/79276803/./test.html"\]"));
driver.switchTo().frame(iframe);

Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:”xpath”,”selector”:”//iframe[contains(@src, “https://stackoverflow.com/questions/79276803/./test.html”)]”}

I was expecting that iframe should be located

Read more here: Source link