Issue
WebElement selectRadioButton;
public void selectContractType(String txt)
{
selectRadioButton.sendKeys(txt);
selectRadioButton.click();
}
Tried like below,
@FindBy(xpath="//*[@class='example-radio-button mat-radio-button mat-accent'][@value='"+txt+"']")
But getting error like this
Solution
You cannot parametrize the WebElement
which was denoted by @FindBy
annotation. @FindBy
annotation purpose is to initialize the elements while initializing the class as part of PageFactory
. You need to do something like below,
Call this below into your method.
WebElement element = createWebElement("//*[@class='example-radio-button mat-radio-button mat-accent'][@value="+txt+"]");
Keep the below reusable method in Utility.
public static WebElement createWebElement(String elementText) {
WebElement element = null;
try {
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementText)));
element = driver.findElement(By.xpath(elementText));
} catch (Exception e) {
System.out.println("Exception occurred: " + e);
}
return element;
}
Keep
WebElement element = createWebElement("//*[@class='example-radio-button mat-radio-button mat-accent'][@value="+txt+"]");
inside selectContractType()
method and assign some value to String txt;
Answered By - Nandan A
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.