findElement(By)和findElementBy()有什么区别?

ERJ*_*JAN 1 java selenium webdriver selenium-webdriver

WebElement p1 = (new FirefoxDriver()).findElement(By.xpath("//div[@class = 'site-title']")) ;

WebElement p2 = (new FirefoxDriver()).findElementByXPath("//div[@class = 'site-title']") ;
Run Code Online (Sandbox Code Playgroud)

我做同样的事情:我选择xpath元素,但在第一行,我使用findElement(By.xpath)和第二,我使用整个表达式findElementByXpath.

我仍然使用相同的firefox驱动程序对象!

这是因为By.界面和访问方式不同?

ale*_*cxe 7

根据硒Java绑定的源代码,findElementByXPath()基本上只是一个快捷方式findElement(By.xpath, ...):

public WebElement findElementByXPath(String using) {
    return findElement("xpath", using);
}
Run Code Online (Sandbox Code Playgroud)