Selenium webdriver ?????-????λ
???????????? ???????[ 2013/12/24 16:51:00 ] ???????????????
????webdriver???????API???ж????λ?????id??name??css???????xpath???????css???????λ???Ч?????xpath???Щ?????id??name?????λ?????????Ч??????????
????1??????????????????????????????и??????????????????????λ??????????????????firefox??firebug????????????????????????????????????????firefox?????????selenium IDE?????????????firebug??????????????????????????????????????????????????£????firebug+firefinder????????firefinder???xpath???css???????λ????????????????????????????
????2??????λ???????findElement() ?? findElements()
????findElement() ?÷??????????????????????webElement??????????????????????? eg??driver.findElement(By.id("userID"));
????findElements() ?÷???????????????????WebElement????????????null
????3??WebElement????????????λ??????
ID??driver.findElement(By.id(<elementID>))
Name??driver.findElement(By.name(<elementName>))
className??driver.findElement(By.className(<elementClassName>))
tagName??driver.findElement(By.tagName(<htmlTagName>))
linkText??driver.findElement(By.linkText(<linkText>))
partialLinkText??driver.findElement(By.partialLinkText(<partialLinkText>))
css??driver.findElement(By.cssSelector(<cssSelector>))
xpath??driver.findElement(By.xpath(<xpathQuery>))
|
????4??webelement?????????????????????????????????????????Ч????????????id??name????????????html???????????????????
????ID??λ??driver.findElement(By.id("username"))
????name??λ??driver.findElement(By.name("username"))
????class??λ??driver.findElement(By.className("username"))
?????????У?WebElement??????????????????????д????????????????div?У???????????λ???丸???????λ???????????????£?
????WebElement hello = driver.findElement(By.id("div1")).findElement(By.lindText("hello"));
????5?????WebElements??λ????????????????????д?????????????????????????class?????????myRadio????????????????????????????????????????????????????У??????????????????£?
List<WebElement> radios = driver.findElements(By.className("myRadio"));
for(int i = 0;i<radios.size();i++){
radios.get(i).click();
}
|
????1????????·????λ???
?????磬????????DOM?е?input???????????????????????????????DOM?е?λ????????????????????????DOM?д?????input???????÷????????DOM?е??????????????????????????
????eg??WebElement username = driver.findElement(By.cssSelector("input"));
????????????????????????????λ???????????????????????????????????λ?????
????????÷???????д?driver.findElement(By.cssSelector("#username")); ?е????????id?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11