如何切换到硒框架?
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 红包祝福语简短10字
18 周六早晨祝福语简短