WebElement p1 = (new FirefoxDriver()).findElement(By.xpath("//div[@class = 'site-title']")) ;
WebElement p2 = (new FirefoxDriver()).findElementByXPath("//div[@class = 'site-title']") ;
我在做同样的事情:我通过 xpath 选择元素,但在第一行,我使用 findElement(By.xpath)
进行操作,第二行我使用 whole expression findElementByXpath.
而且我仍然使用相同的 firefox 驱动程序对象!
这是因为 The By. 是接口(interface)并且访问方式不同吗?
最佳答案
根据selenium java bindings的源代码,findElementByXPath()
基本上只是 findElement(By.xpath, ...)
的快捷方式:
public WebElement findElementByXPath(String using) {
return findElement("xpath", using);
}
关于java - findElement(By) 和 findElementBy() 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29065653/