Can anyone help me, i want to make my looping stop when find the object with verifyElementPresent, but when the object found, the looping still going and open new browser, but log in with another username, how to make the looping stop??, here is my script.
WebUI.openBrowser(‘’)
WebUI.navigateToUrl(‘https:testing.com’)
WebUI.maximizeWindow()
for (def rowNum = 1; rowNum <= findTestData(‘Login’).getRowNumbers(); rowNum++) {
WebUI.setText(findTestObject('Object Repository/Log_IN/Page_Testing/input_Sign In To Testing_username'), findTestData(
'Login').getValue(1, rowNum))
WebUI.setText(findTestObject('Object Repository/Log_IN/Page_Testing/input_Sign In To Testing_password'), findTestData(
'Login').getValue(2, rowNum))
WebUI.click(findTestObject('Object Repository/Log_IN/Page_Testing/button_Sign In'))
if (WebUI.verifyElementPresent(findTestObject('Object Repository/Log_IN/Page_Testing/Apuppt'), 3, FailureHandling.OPTIONAL))
{
WebUI.click(findTestObject('Object Repository/Log_IN/Page_Testing/Clickbutton'))
break ;
}
WebUI.delay(2)
A method to “break” out of your loop is to use the break command, like you have below. However, if you have multiple “levels” of if conditions and loops, then you need to use: break label (the label can be any word except reserved ones), like break Loop; (as below). Put the label above your for loop and then your loop will exit all “levels”.
How about adding the above statement? It might be looping 4 times because the text you are looking for is not present yet as the page may be forming. You sometimes have to slow your script down to allow your web page to form and elements to appear.
And perhaps the below as well:
WebUI.waitForElementVisible(findTestObject('Object Repository/Log_IN/Page_Testing/input_Sign In To Testing_username'))
WebUI.setText(findTestObject('Object Repository/Log_IN/Page_Testing/input_Sign In To Testing_username'), findTestData( 'Login').getValue(1, rowNum))
WebUI.setText(findTestObject('Object Repository/Log_IN/Page_Testing/input_Sign In To Testing_password'), findTestData('Login').getValue(2, rowNum))
WebUI.click(findTestObject('Object Repository/Log_IN/Page_Testing/button_Sign In'))
WebUI.waitForElementPresent(findTestObject('Object Repository/Log_IN/Page_Testing/Apuppt'), 10)
if (WebUI.verifyElementPresent(findTestObject('Object Repository/Log_IN/Page_Testing/Apuppt'), 3, FailureHandling.OPTIONAL))
{
WebUI.click(findTestObject('Object Repository/Log_IN/Page_Testing/Clickbutton'))
break Pizza; // here we call the label to break out of all loops
}
Probably a troll of a response, that I’m about to make…
…but I can’t help but question the veracity of this approach…
Should we really be brute-forcing every user login, just to find an element on the page (presumably corresponding to some data about that user)?
How’s come we don’t just log in, with some manager-level user, and look up that piece of data on the page (and who it applies to? For example, an upcoming appointment or member status…