Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Webdriver' - 4 code snippet(s) found

 Sample 1. Selenium - Get the element using WebDriver

WebElement element = driver.findElement(By.id("elementId"));

// or use annotation @FindBy as following

@FindBy(id = "elementId")
WebElement element;

   Like      Feedback     selenium  webdriver  automation testing


 Sample 2. Select an option using the select element name and the expected option value

void select(String name, String value) {
WebElement element = By.name(name);
List<WebElement> options = element.findElements(By.tagName("option"));
for (WebElement option : options) {
if (option.getText().equals(value)) {
option.click();
return;
}
}
}

   Like      Feedback     selenium  webdriver  webelement


 Sample 3. Selenium - WebDriver - Method to check if an option has already been selected

boolean isSelected(String selectName, String optionValue) {
WebElement element = By.name(name);
List<WebElement> options = element.findElements(By.tagName("option"));
for (WebElement option : options) {
if (option.getText().equals(value)) {
return option.isSelected();
}
}
return false;
}

   Like      Feedback     selenium  webdriver  WebElement


 Sample 4. Wait till Page loads in selenium / Web Driver

public void waitTillPageLoads() {

ExpectedCondition < Boolean > expectedCondition = driver -> ((JavascriptExecutor) driver).executeScript("return document.readyState").toString().equals("complete");
try {
WebDriverWait wait = new WebDriverWait(driver, 90);
wait.until(expectedCondition);
driver.quit();
} catch (Exception exception) {

}
}

   Like      Feedback     selenum  webdriver



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner