1. 程式人生 > >selenium+java 定位方法 findElement 之 By xpath

selenium+java 定位方法 findElement 之 By xpath

通過xpath定位,xpath定位有N種寫法,列幾個常用寫法:

id:
driver.findElement(By.xpath("//*[@id='kw']"))
name:
driver.findElement(By.xpath("//*[@name='wd']"))
className:
driver.findElement(By.xpath("//input[@class='s_ipt']"))
css:
driver.findElement(By.xpath("/html/body/form/span/input"))
form:
driver.findElement(By.xpath("//form[@id='form']/span/input"))
id和name定位:
driver.findElement(By.xpath("//input[@id='kw' and @name='wd']"))