从Selenium docs开始,WebDriver是一个接口,但在Eclipse中,包org.openqa.selenium
在Project Explorer中显示为一个类。此外,如果WebDriver是一个接口,那么实现它的ChromeDriver或InternetExplorerDriver等类应该定义.get()
或.getCurrentUrl()
等方法。我们在哪里可以看到这些方法的方法定义?
答案 0 :(得分:6)
WebDriver是一个公共界面,我不认为ChromeDriver或任何其他驱动程序实现WebDriver,而是扩展 RemoteWebDriver 这是一个类。
修改强>
正如我所说,驱动程序扩展了RemoteWebDriver,并且具有这些方法的实际实现。
public void get(String url) {
execute(DriverCommand.GET, ImmutableMap.of("url", url));
}
Java源代码:
public interface WebDriver extends SearchContext {
// Navigation
/**
* Load a new web page in the current browser window. This is done using an HTTP GET operation,
* and the method will block until the load is complete. This will follow redirects issued either
* by the server or as a meta-redirect from within the returned HTML. Should a meta-redirect
* "rest" for any duration of time, it is best to wait until this timeout is over, since should
* the underlying page change whilst your test is executing the results of future calls against
* this interface will be against the freshly loaded page. Synonym for
* {@link org.openqa.selenium.WebDriver.Navigation#to(String)}.
*
* @param url The URL to load. It is best to use a fully qualified URL
*/
答案 1 :(得分:1)
WebDriver是一个公共接口,我们只定义一个类型为interface的引用变量(driver)。现在我们分配给它的任何对象必须是实现接口的类(fireFoxDriver)的实例。