编写 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.com/index.htm";
// launching the URL
driver.get(url);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("Page loaded successfully");
driver.close();
}
}
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP