一:Chrome
注意设置驱动:
System.setProperty("webdriver.chrome.driver", "D:\\IDEA_JAVA_PRJ\\selenuim\\src\\main\\resources\\webDriver\\chromedriver.exe");
ChromeDriver chromeDriver = new ChromeDriver();
二: By.className 当class有多个属性时,使用cssSelector
如果元素指定了若干个class属性值的“复合样式”的情况就使用cssSelector,如<input id="su" class="bg s_btn" type="submit" value="百度一下">
driver.findElement(By.cssSelector("input.bg.s_btn")).sendKeys("Hello, world"); 或者cssSelector(".bg.s_btn")
input.bg.s_btn 也可写成 input[class='bg s_btn']
cssSelector: 样式使用‘’.‘’连接多个属性,且第一个属性前面也要加".";
xpath和css对应写法
Direct child //div /a ---------- div > a
Child //div //a ---------- div a
Match sub string
css=input[id^='aaa'] ---------- input element id start with aaa
css=input[id*='aaa'] ---------- input element id contains aaa
css=input[id$='aaa'] ---------- input element id end with aaa
Match innner text
css=input:contains('aaa') ---------- input element inner text contains aaa
css=input:not(contains('aaa')) ---------- input element which inner text not contains aaa
Use several attribute to describe
input[class='aa'] [type='button']