selenium详细api

se 个人 ee  企业  me移动   jvm  jre环境  jdk工具包

 

StreamBroswer s=new StreamBroswer()

s.FinishProcess("Firefox.exe")

 

Driver

1.new FirefoxDriver(p)

FirefoxProflie p=new FirefoxProfile(new file(""))

2.new ChromeDriver

System.setProperty("webdriver.chrome.driver",path)

3.new InternetExplorerDriver

System.setProperty("webdriver.ie.drvier",path)

 

 

ChromeDriverService service = new ChromeDriverService.Builder() . usingDriverExecutable (new File("E:\\SeleniumWebDriver\\chromedriver_win_23.0.1240.0\\chromedriver.exe")).usingAnyFreePort().build();
service.start();
driver = new ChromeDriver();
driver.get("http://www.baidu.com");
driver.quit();
// 关闭 ChromeDriver 接口
service.stop();

 

定位

By.id

By.xpath

By.cssSelector

By.className

By.linkText

By.tagName

By.name

By.paritialLinkText  部分链接文字进行匹配

 

xpath

/ 根节点  //从匹配中选择,不考虑位置 . 当前节点  ..当前节点父节点  @元素属性

div 选取div的所有子节点

/book[last()-1]

/title[contains(text(),'') and @lang='']   /title[contains(text(),'')][@lang='']]

/title[starts-with(@lang,'') or @id='']

/bookPrice[price>35]

/book/title | /book/a  /book/title & /book/a

 

 

 

submit

element.submit   getAttribute("style")

isEnabled  isDisplayed  isSelected

 

Navigate

driver.Navigate.to/back/forward/refresh

 

Manage

driver.manage.window.maxmize/getSize/getPosition

driver.manage.addCookies

drvier.manage.timeouts.implicitlyWait

 

switchTo

driver.switchTo.alert.accept/dismiss

driver.switchTo.defaultContent

driver.switchTo.frame(index/idOrName/webelement)

driver.switchTo.parentFrame()

driver.switchTo.window(windowname)

set<>=driver.getWindowHandles

 

 

Select

Select s=new Select(element)

s.selectByIndex(0)

s.selectByValue("")

s.selectByVisibleText("")

 

Action

Action a=new Action(driver)

a.moveToElement(element).click().perform();  移动到

a.clickAndHold(element).perform();  按住不放

a.doubleClick(element).perform();

a.contentClick(element).perform()  右键

a.drapAndDrop(source, target).perform();

a.clickAndHold(source). moveToElement (target).perform()

a.release()

 

a.keyDown(key.SHIFT) 按下

a.keyUp(key.CRTL) 释放

a.keyDown().keyUp().perform();

a.keyDown().sendKeys("").perform();

a.keyDown(Keys.CONTROL).sendKeys("v").perform();

 

 

显性等待:

明确等待某个元素出现或者可以点击,等不到就一直等,直到timeout抛出exception

webElemenet e=

(new webDirverWait(driver,10)).until(ExpectedConditions.presenseOfElementLocated(element));

 

隐性等待:

全局等待,对所有元素设置统一的超时时间

driver.manage.timeouts.implicitlyWiat(second.TimeUnit.SECONDS)

 

testng

BeforeClass

BeforeTest

Test

Assert.assertTure/assertEquals(e,a)

 

suite/test/classes/class name=/method preserve-order/<include name>

<listener  class-name="">

test/<parameter name=" browser "  value="">

@parameter({"browser"})

 

框架使用:

log.deBug()

log.writeErrorLog()

 

 

1.Startbrowser.setUp("")

2.page=new Page(driver)

3.manage.window.maxmize

4.(1)objectHandle.browserHandle("")/frameHandle/checkboxHandle/dateHandle(driver,element,2013,12,12)

(2)FrameFunction f=new FrameFunction;

 

page.getElement()

 

posted @ 2016-03-28 22:00  q55091  阅读(222)  评论(0编辑  收藏  举报