use of org.openqa.selenium.support.pagefactory.ByChained in project selenium_java by sergueik.
the class SuvianTest method test5_3.
// origin:
// https://www.programcreek.com/java-api-examples/index.php?api=org.openqa.selenium.support.pagefactory.ByChained
// https://www.javatips.net/api/org.openqa.selenium.support.pagefactory.bychained
@Test(enabled = true)
public void test5_3() {
// Arrange
driver.get("http://suvian.in/selenium/1.5married_radio.html");
String label = "yes";
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(".container .row .intro-message h3 a"))));
WebElement formElement = driver.findElement(By.cssSelector(".intro-header .container .row .col-lg-12 .intro-message form"));
String elementContents = formElement.getAttribute("outerHTML");
String line = new ArrayList<String>(Arrays.asList(elementContents.split("<br/?>"))).stream().filter(o -> o.toLowerCase().indexOf(label) > -1).findFirst().get();
Matcher matcher = Pattern.compile("value=\\\"([^\"]*)\\\"").matcher(line);
String checkboxValue = null;
if (matcher.find()) {
checkboxValue = matcher.group(1);
System.err.println("checkbox value = " + checkboxValue);
} else {
System.err.println("checkbox value not found");
}
WebElement checkBoxElement = null;
if (checkboxValue != null) {
ByChained byChained = new ByChained(By.xpath("//body/*"), By.cssSelector(".intro-header .container .row .col-lg-12 .intro-message form"), By.cssSelector(String.format("input[name='married'][value='%s']", checkboxValue)));
checkBoxElement = driver.findElements(byChained).get(0);
}
// Act
assertThat(checkBoxElement, notNullValue());
highlight(checkBoxElement);
checkBoxElement.click();
sleep(500);
// Assert
assertTrue(checkBoxElement.isSelected());
}
Aggregations