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

标签 java selenium selenium-webdriver webdriver

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/

相关文章:

java - 互换 HashSet 和 TreeSet

selenium - DefaultSelenium 和 RemoteWebDriver 有什么区别?

ruby - headless (headless)操作在 Sinatra 路由中不起作用

c# - 如何在 Selenium 中使用 Telerik 下拉菜单?

python - 使用 Selenium 和partial_link_text 抓取 html 元素

java - 如何在方法中使用 doGet 响应?

java - 登录时显示用户电子邮件 (JSF 2.0)

Java - Thread join() 和执行顺序 SCJP 问题?

java - 如何将图像保存到android中的Camera文件夹?

java - org.openqa.selenium.SessionNotCreatedException : session not created exception from tab crashed error when executing from Jenkins CI server