Cool thing happen today:) Envrioment set up and Seleniumn can run. Let ' s explore the Selenium-webdirver
Save the Comand as bat, so next time just double click on It.than it'll up the Senelium server
Selenium-stand Along.jar is a webdrive (on webdrive and romete control, please see Wike or Baidu or Google
- Fire Fox Demo
Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver;ImportOrg.openqa.selenium.chrome.*;Importorg.openqa.selenium.support.ui.ExpectedCondition;Importorg.openqa.selenium.support.ui.WebDriverWait; Public classWeb { Public Static voidMain (string[] args) {//Create a Firefox driver instanceWebdriver Driver =NewFirefoxdriver (); //Open Test URLDriver.get ("https://apps.na.collabserv.com/");//define user name and password text boxesWebelement username=driver.findelement (by.id ("username")); Webelement Password=driver.findelement (by.id ("Password")); //Enter user name and passwordUsername.sendkeys ("[Email protected]"); //webelement continuevisit=driver.findelement (by.id ("continue"));Password.sendkeys ("Test"); //Click Login to log inWebelement login=driver.findelement (by.id ("Submit_form")); Login.click (); //set the page to wait until the Mail link appears(NewWebdriverwait (Driver, $)). Until (NewExpectedcondition<webelement>(){ Publicwebelement Apply (Webdriver dr) {returnDr.findelement (By.linktext ("Mail")); } }); //Log OutWebelement logout=driver.findelement (By.linktext ("Log out")); Logout.click (); //Close BrowserDriver.quit (); }}
2, chrome demo-note chrome is different with IE and FIrefox. It is need to download a chromedriver.exe under same root as Chrome.exe also need to set property. C Ompare the demo, find difference
Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver;ImportOrg.openqa.selenium.chrome.*;Importorg.openqa.selenium.support.ui.ExpectedCondition;Importorg.openqa.selenium.support.ui.WebDriverWait; Public classWeb { Public Static voidMain (string[] args) {//Create a Firefox driver instanceSystem.setproperty ("Webdriver.chrome.driver", "C:\\Program Files\\google\\chrome\\application\\chrome.exe" ); Webdriver Driver=NewChromedriver (); //Open Test URLDriver.get ("https://apps.na.collabserv.com/");//define user name and password text boxesWebelement username=driver.findelement (by.id ("username")); Webelement Password=driver.findelement (by.id ("Password")); //Enter user name and passwordUsername.sendkeys ("[Email protected].com")); //webelement continuevisit=driver.findelement (by.id ("continue"));Password.sendkeys ("Test"); //Click Login to log inWebelement login=driver.findelement (by.id ("Submit_form")); Login.click (); //set the page to wait until the Mail link appears(NewWebdriverwait (Driver, $)). Until (NewExpectedcondition<webelement>(){ Publicwebelement Apply (Webdriver dr) {returnDr.findelement (By.linktext ("Mail")); } }); //Log OutWebelement logout=driver.findelement (By.linktext ("Log out")); Logout.click (); //Close BrowserDriver.quit (); }}
Helpful Address:
http://www.ibm.com/developerworks/cn/web/1309_fengyq_seleniumvswebdriver/
Http://www.open-open.com/lib/view/open1354764154148.html
http://qa.blog.163.com/blog/static/19014700220122231779/
Selenium_java-2 Some Demo for Firefox &chrome