I am trying to get an xpath for a certain button/Frame. I am able to locate the element using the xpath but while running automation I am getting element not found exception. I tried to switch to the particular frame and then finding the button but it did'nt work. Attaching the link for the page and Image.
Link : https://www.msn.com/en-in/weather/today/New-Delhi,Delhi,India/we-city-28.608,77,201?iso=IN
Here is the code I tried.
WebDriverWait wait = new WebDriverWait(cdriver,30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='foot']//following::iframe[@style='width:9.7rem;']")));
System.out.println("Ive waited for the frame to load");
int size = cdriver.findElements(By.tagName("iframe")).size();
System.out.println(size);
/*for(int i=0; i<=size; i++){
cdriver.switchTo().frame(i);
System.out.println("Switched to frame "+i);
int total= cdriver.findElements(By.xpath("//*[@id='u_0_0']/div/button/span")).size();
System.out.println(total);
cdriver.switchTo().defaultContent();
}*/
cdriver.switchTo().frame(2);
System.out.println("Switched to frame");
cdriver.findElement(By.xpath("//*[@id='u_0_0']/div/button/span")).click();
Getting the number of frames present and then checking in each for the element but its not able to switch to the frame.