WebUI.waitForPageLoad(3)
CustomKeywords.'userTable.sidebar.sidebarUsersClick'()
WebUI.setText(findTestObject('Object Repository/Overview Page Objects/overview searchbar'), "Tester") //Search for the user.
List<WebElement> rows = WebUI.findWebElements(findTestObject('Object Repository/Overview Page Objects/patientList_Row'), 10) //create list from user results after search
for(int i = 1 ; i < rows.size() ; i++) {
WebElement row = rows.get(i) //get the current row element
WebElement firstCell = row.findElement(By.xpath(".//div[@data-field='nameSurname']")) // get the text of the first cell (username and surname)
String user = firstCell.getText()
println user
if(user.equals("QA Tester")) {
WebElement deleteIcon = row.findElement(By.xpath("//a[@aria-label='Delete']"))
deleteIcon.click()
WebUI.click(findTestObject('Object Repository/Users Page Objects/Add Patient Details/deleteButton'))
}
}
Basicly in this code block. Firstly im searching a user name in searchbox, then make a List for the results of users, and creating loop for to find the user i want (QA Tester), then when loop finds the user i want, i want it to click the Delete Icon. when i run this code. The loop ends successfully, but does not click the delete icon.
Which browser do you use? Chrome?
Could you try the test with other type of browser?
How does it work with FireFox?
im sorry but i can’t, tried to update driver of other browsers but im having a problem with updating right now, so chrome is the only option i can use, and yeah im using chrome
when i put the code outside of the if&for loop it works, but inside its not working, i was thinking about maybe the problem is in if statement?
I have no idea how your code would/should work. Please help yourself.
First thing I see is that you do not exit your loop when you find your “QA Tester”. You don’t have to but it would make your loop more efficient; you find it and get on with your other tasks, instead of spinning more times than need be.
Pizza: // need a label here; any label
for (int i = 0 ; i < rows.size() ; i++) { // what about the first row, row 0
WebElement row = rows.get(i) //get the current row element
WebElement firstCell = row.findElement(By.xpath(".//div[@data-field='nameSurname']")) // get the text of the first cell (username and surname)
String user = firstCell.getText()
println ">${user}<" // just checking if there are spaces
if (user == "QA Tester") { // maybe user.contains("QA Tester")
WebElement deleteIcon = row.findElement(By.xpath("//a[@aria-label='Delete']"))
deleteIcon.click()
WebUI.click(findTestObject('Object Repository/Users Page Objects/Add Patient Details/deleteButton'))
break Pizza; // we exit the loop after finding our prize
}
}
Edit: instead of if (user.equals("QA Tester"))
, maybe you can use:
if (user == "QA Tester") {
or
if (WebUI.verifyMatch(user, "(?i)QA Tester", true)) {
or
if (user.contains("QA Tester")) {
2 Likes
if i use .//div[@data-field='nameSurname'] xpath in console it prints both QA Tester and Male,23yo if i change the xpath for only QA Tester part it never shows in the console should i trim the both words? also with (user == "QA Tester") it completed the loop again but didint click.
for (int i = 1; i < rows.size(); i++) {
WebElement row = rows.get(i)
WebElement firstCell = row.findElement(By.xpath(".//div[@data-field='nameSurname']"))
String user = firstCell.getText()
println ">${user}<"
if (user.contains("QA Tester")) {
WebElement deleteIcon = row.findElement(By.xpath("//a[@aria-label='Delete']"))
deleteIcon.click()
WebUI.click(findTestObject('Object Repository/Users Page Objects/Add Patient Details/deleteButton'))
break
}
}
now its working thank you! I tried contains before but it didint work that time, now its working
1 Like
Thanks @grylion54 for your solution!!!