編寫 Web 驅動程式指令碼的最基本步驟是什麼?
編寫 Web 驅動程式指令碼的最基本步驟如下 −
透過建立一個指向相應瀏覽器驅動程式類的 webdriver 參考,開啟任何瀏覽器。
使用 get() 方法啟動任何 URL。
暫停一段時間以用於頁面載入。
確認我們正處於正確的網頁上。
最後關閉會話。
程式碼實現
示例
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 WebScripting { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/index.htm"; // launching the URL driver.get(url); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); System.out.println("Page loaded successfully"); driver.close(); } }
廣告