我面临一个奇怪的问题。我的申请有框架。我成功地能够切换到框架,但仍然webdriver无法定位该框架上的元素。我甚至尝试定位元素而不切换到框架,但显然这也不起作用。
我写过的代码:
driver.findElement(By.xpath("//*[@id='authorized']/div[2]/div/div/a/div")).click();
Thread.sleep(6000);
driver.findElement(By.linkText("I am having picture problems")).click();
Thread.sleep(2000);
//Assume driver is initialized properly.
List<WebElement> ele = driver.findElements(By.tagName("iframe"));
System.out.println("Number of frames in a page :" + ele.size());
for(WebElement el : ele){
//Returns the Id of a frame.
System.out.println("Frame Id :" + el.getAttribute("id"));
//Returns the Name of a frame.
System.out.println("Frame name :" + el.getAttribute("name"));
}
driver.switchTo().frame("lightboxFrame");
Thread.sleep(1000);
driver.findElement(By.xpath("//html/body/div[1]/div/div[2]/div/div/a/span/span")).click(); //This line fails