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']"))

猜你喜欢

转载自blog.csdn.net/qq_36969649/article/details/83576696