1)方法driver1的調用:
1 @BeforeClass
2 public void setUp() throws Exception {
3 // 啟動腳本
4 startScript(getClassName());
5 // 啟動浏覽器
6 driver(Config.browserPath, Config.browserDriverPath);
7 driver1(Config.webUrl1);
8 }
2)方法driver1的實作,在方法裡面使用顯示等待,代碼如下:
1 //打開指定的URL
2 public static WebElement driver1(String webUrl) throws Exception {
3 // 讓浏覽器通路 web
4 Debug("URL: " + webUrl);
5 driver.get(webUrl);
6 WebElement e = (new WebDriverWait( driver, 10 )) .until(
7 new ExpectedCondition< WebElement>(){
8 public WebElement apply( WebDriver d) {
9 return d.findElement( By.xpath( ".//*[@id='test-top-tab']/table/tbody/tr/td[1]/table/tbody/tr/td[1]/table/tbody/tr/td[2]" ));
10 }
11 });
12 // 擷取 網頁的 title
13 log("打開頁面: " + driver.getTitle());
14 return e;
15 }
轉載于:https://www.cnblogs.com/dingziyin/p/4906304.html