Explore and practice, make mistakes and fix them, learn a few techniques, have fun.
- It's an open source tool that is supported by a great community.
- It allows QA engineers to write/run test cases in Java, C#, Python, JavaScript, Ruby, and a few more...
- It makes it easy to implement test cases, just need to know how to locate a web element in the browser and perform actions.
anything you can find on a web page: text boxes, checkboxes, radio buttons, dropdowns, links, etc. Each element has a unique identifier, such as ID, name or unique classes. A web element can be located by ID, XPath or CSS Selectors.
Click each element to learn how to perform action using Selenium WebDriver Java API
WebElement element = driver.findElement(By.cssSelector(label));
String js = "arguments[0].setAttribute('value','"+text+"')";
((JavascriptExecutor) driver).executeScript(js, element);
public String switchToNewWindow(WebDriver driver)
{
String parentWind = driver.getWindowHandle();
for (String childWin : driver.getWindowHandles()) {
driver.switchTo().window(childWin);
}
return parentWind;
}
public void switchToParentWindow(WebDriver driver, String parentWindow)
{
driver.close();
driver.switchTo().window(parentWindow);
}
public void switchToIFrame(WebDriver driver, String iframeId)
{
WebElement iframeSwitch = driver.findElement(By.id(iframeId));
driver.switchTo().frame(iframeSwitch);
}
public void switchToParentWindow(WebDriver driver)
{
driver.switchTo().defaultContent();
}
JavascriptExecutor executor = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.xpath("xpath"));
executor.executeScript("arguments[0].scrollIntoView();", element);
TakesScreenshot image =(TakesScreenshot) driver;
File srcfile=image.getScreenshotAs(OutputType.FILE);
File desfile=new File("file-with-path");
FileUtils.copyFile(srcfile, desfile);
WebElement webel = driver.findElement(By.xpath("//*[@id=\"submit_it\"]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", webel);
wait.until(ExpectedConditions.alertIsPresent());
String alertText = driver.switchTo().alert().getText();
driver.switchTo().alert().accept();
© CollColl-2020 | |
Java source code | |
Practice more |