如何切换到硒框架?
switchTo()defaultContent()
此方法用于在帧和父帧之间来回切换。焦点转移到主页上。
switchTo()。parentFrame()
此方法用于将控件切换到当前帧的父帧。
示例
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class FrameDefault {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "url with frames";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
//在索引的帮助下抓取第一帧
driver.switchTo().frame(0);
System.out.println("Getting the page source " + driver.getPageSource());
//切换回父网页
driver.switchTo().defaultContent();
driver.quit();
}
}热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短