I wish to automate a scenario, where in a data grid I have a checkbox for Status for a user, whether the user is active or not, now what I am doing is:
1. Creating a list of checkboxes on the Grid, and if the size > 0 then I gettext() of the first record in the grid and store it in a string variable.
2. Send the data of the string variable in the search-box and the user appears, now I click the checkbox and if it is inactive then it becomes active, and vice-versa.
Now I want to verify that the checkbox gets selected/clicked and the status changes on click, but not sure how do I verify it, that an active becomes inactive and vice-versa.
Can someone please suggest how do I go about this scenario?
<input type="checkbox" class="custom-control-input" onclick="activeChange(this)" id="chkIsActive_6" checked="checked">
When Checkbox is selected or the user is "Active""
<input type="checkbox" class="custom-control-input" onclick="activeChange(this)" id="chkIsActive_6">
When Checkbox is unselected or the user is "Inactive""
CodePudding user response:
There is different attribute between Active and Inactive element.
Actually you can achieve with .getAttribute("checked")
, see the below approach:
//get current element
WebElement elementBefore = driver.findElement(By.id("chkIsActive_6"));
String before = elementBefore.getAttribute("checked");
//do something here to make the element change, maybe click event
...
//ideally insert a wait here
...
//get element after action
WebElement elementAfter = driver.findElement(By.id("chkIsActive_6"));
String after = elementAfter.getAttribute("checked");
//verify
if(!after.equals(before)) {
//successfully changed
}
CodePudding user response:
Try using isSelected() method:
isChecked = webElement.findElement(By.id("chkIsActive_6")).isSelected();