"CL" Selenium Example 2: Open Baidu, enter Hello World

Source: Internet
Author: User

/* The class created is JUnit class*/

Package Selenium_lassen;

Import static org.junit.assert.*;

Import Java.io.File;

Import Org.junit.After;
Import Org.junit.Before;
Import Org.junit.Test;
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import org.openqa.selenium.WebElement;
Import Org.openqa.selenium.firefox.FirefoxBinary;
Import Org.openqa.selenium.firefox.FirefoxDriver;
Import org.openqa.selenium.remote.DesiredCapabilities;

public class Case2 {

Webdriver driver;
@Before
public void SetUp () throws Exception {
Method One
System.setproperty ("Webdriver.firefox.bin", "D:\\ruanjian\\firefox\\azml\\firefox.exe");
Method Two
Desiredcapabilities Capability=desiredcapabilities.firefox ();
Capability.setcapability ("Firefox_binary", "D:\\ruanjian\\firefox\\azml\\firefox.exe");
Driver = new Firefoxdriver (capability);
Method Three
File Pathtofirefoxbinary = new file ("D:\\ruanjian\\firefox\\azml\\firefox.exe");
Firefoxbinary firefoxbin = new Firefoxbinary (pathtofirefoxbinary);
Driver = new Firefoxdriver (firefoxbin,null);
}


@Test
public void Test () throws exception{
Driver.get ("http://www.google.com.hk");
webelement element = Driver.findelement (By.name ("Q"));
Element.sendkeys ("Hello selenium!");
Element.submit ();
}

@After
public void TearDown () throws Exception {
System.out.println ("page title is:" +driver.gettitle ());
Driver.quit ();
}

}

"CL" Selenium Example 2: Open Baidu, enter Hello World

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.