首先,我們必須在這幀的gettext的存在識別,然後切換到特定的幀,然後找到元素。
語法:
driver.switchTo().frame("frameName"); //name of the frame
driver.switchTo().frame(1); //index
例子:
driver.switchTo().frame(1);
driver.findElement(By.xpath("//p")).getText();
driver.switchTo().defaultContent();
注:
driver.switchTo().defaultContent(); //Used default frame, I.E. If there are three frames in one page named as 1,2,3. If you want to switch from frame 2 to frame 3, In that case we are not able to switch directly to the frame 3, In this case what we have to do is
driver.switchTo().frame("2"); //frame 2
driver.switchTo().defaultContent();// main window - (Default page) while loading webpage
driver.switchTo().frame("3"); //frame 3
請找出原因如下路徑:StaleElementException
- 該元素已被完全刪除。
- 的元件不再連接到DOM
http://www.seleniumhq.org/exceptions/stale_element_reference.jsp