Selenium_java-2 Some Demo for Firefox &chrome

Source: Internet
Author: User

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

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.