selenium+java 元素定位
一、单个元素定位: 以百度查询为例,如图: 1.id定位,findElement(By. id (" ")) driver.findElement(By.id("kw")).sendKeys("新闻"); 2.name定位,findElement(By. name (" ")) driver.findElement(By.name("wd")).sendKeys("新闻"); 3. className定位,findElement(By.className(" ")) driver.findElement(By.className("s_ipt")).sendKeys("新闻"); 4. xpath定位,findElement(By.xpath(" ")) driver.findElement(By.xpath("//*[@id='kw']")).sendKeys("新闻"); 5. cssSelector定位,findElement(By.cssSelector(" ")) driver.findElement(By.cssSelector("#kw")).sendKeys("新闻"); 6. tagName定位,findElement(By.tagName("input")) driver.findElement(By.tagName("input")).sendKeys("新闻