You can install and test Selenium using the following steps.
All files can be downloaded from http://www.seleniumhq.org/download/
- Download Selenium Server jar file
- Download client library java jar file
- Download InternetExplorer Driver file
- Install eclipse workspace. (download eclipse. Unzip folder. Find eclipse.exe application and open it)
- Create a new java project with 1,2 as references
- Copy 3 to workspace
- For IE, go to internet options->security and change the security level so that it’s the same for all zones.
- Write sample java program
Below program opens google in IE and searches for selenium test and closes it.
// All the imports happen automatically when you use eclipse ide and add the downloaded jars in the project references
package test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class googlesearch {
public static void main(String[] args) throws Exception {
NewTest t=new NewTest();
t.test();
}
}
class NewTest {
public void test() throws Exception
{
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
final WebDriver driver=new InternetExplorerDriver();
driver.get("http://www.google.com");
//Alert is to handle pop ups
//Alert alert=driver.switchTo().alert();
//alert.accept();
WebElement myelm=(new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
driver.findElement(By.name("q")).sendKeys("selenium test");
driver.findElement(By.name("q")).submit();
driver.quit();
}
}
//alert.accept();
WebElement myelm=(new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
driver.findElement(By.name("q")).sendKeys("selenium test");
driver.findElement(By.name("q")).submit();
driver.quit();
}
}
Comments
Post a Comment