辅助工具: chrome浏览器,F12打开控制台;
Firefox浏览器,F12打开控制台;
或者选中要定位的元素右键
安装firefox扩展firebug和firepath;
安装之后F12可调用firebug;
firepath内嵌在firebug中;
选中要定位的页面元素,右键可以获得该元素的xpath和css路径,方便使用xpaht和css方式定位元素,在firepath中可以自己输入xpath表达式和css表达式来定位元素。
1.通过ID定位
public staticBy id(String id)
Parameters:
id- The value of the "id" attribute to search forReturns:
a By which locates elements by the value of the"id" attribute.
之前例子中用到的:
WebElement searchButton = driver.findElement(By.id("stb"));
就可以获取到该元素.
2.通过name定位
public staticBy name(String na