0

I have a webpage where different action buttons are available. I am identifying the action buttons using the CSS selector. I want to have a common method to click on the action buttons using the parameter of method. All the buttons have similar attributes but different values.

Please look into the code.

public static void TakeAction(WebDriver driver, String Action)
{
    WebElement btnAction= driver.findelement(By.cssSelector("input[type='button'][value='Action']").
    btnAction.click();
}

Now this [value='Action'] -> Action should be picked from the method parameter however i am not able to figure out the syntax to specify the same.

Any help will be appreciated.

1 Answer 1

1

Just gave few attempts and got the syntax.

WebElement btnAction= driver.findelement(By.cssSelector("input[type='button'][value='"+Action+"']").
Sign up to request clarification or add additional context in comments.

1 Comment

Yep that is what I was going to suggest. In the way you put it at first, "Action" was part of the string "input[type='button'][value='Action']", not a variable. So you have to split those parts that have to be fed using +. Well solved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.