For example, I need a common function that clicks a button given the button text. I don't want to have to keep writing this long code snippet:
(new WebDriverWait(driver, waitSeconds)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(CssFormButtonBegin+buttonText+CssFormButtonEnd))).click();
Instead, I would like to use a common function like:
public void clickButton(String buttonText) {
getButton(String buttonText);
}
public void getButton(String buttonText) {
// code that gets the WebElement of button type in CssSelector
// cssDoesNotWork = "button:contains('buttonText')"
// cssWorks = "form.className button#buttonId"
// or
// cssButtons = "form.className button"; // and loop through button list to find exact button by buttonText
}
Note that I use the CssSelector instead of the XPath to get the button element.
No comments:
Post a Comment