Issues with IFrame

Please help me with this:
Received the following error when I executed automated Test Cases;

Test Cases/Online Order FAILED because (of) Unable to switch to iframe (Root cause: java.lang.NullPointerException)

Error is received in the following line:
WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

Following is the code I have been using:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘http://giftweb-sit.ad.scentregroup.com/RPortal’)

WebUI.click(findTestObject(‘Page_Buy Westfield Gift Cards Onlin/a_Buy Now’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/button_Add to cart’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/li_50’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/div_Go back’))

WebUI.setText(findTestObject(‘Page_Buy Gift Cards Online Westfie/input_Value’), ‘70’)

WebUI.setText(findTestObject(‘Page_Buy Gift Cards Online Westfie/input_Quantity’), ‘1’)

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/button_Add to Cart (1)’))

WebUI.click(findTestObject(‘Page_/input_ContactType’))

WebUI.setText(findTestObject(‘Page_/input_ActivationCommunicationT’), ‘swapnareddyj@gmail.com’)

WebUI.setText(findTestObject(‘Page_/input_ActivationCommunicationT_1’), ‘swapnareddyj@gmail.com’)

WebUI.click(findTestObject(‘Page_/button_Proceed to Checkout’))

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.FirstName’), ‘swapna’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.LastName’), ‘reddy’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.StreetAdd’), ‘targo road’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.Suburb’), ‘girraween’)

WebUI.selectOptionByValue(findTestObject(‘Page_/select_SelectNSWACTNTQLDSATASV’), ‘NSW’, true)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.PostCode’), ‘2145’)

WebUI.setText(findTestObject(‘Page_/input_EmailAddress’), ‘swapnareddyj@gmail.com’)

WebUI.setText(findTestObject(‘Page_/input_Phone’), ‘123456’)

WebUI.click(findTestObject(‘Page_/span_Next’))

WebUI.click(findTestObject(‘Page_/input_PaymentType’))

WebUI.click(findTestObject(‘Page_/input_AcceptTermsAndConditions’))

WebUI.click(findTestObject(‘Page_/button_Place order’))

WebUI.switchToFrame(findTestObject(‘Page/_ifr_EWAY_CARDNUMBER’), 5)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

WebUI.click(findTestObject(‘Page_/div_id(katalon-elementInfoDiv)’))

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNAME’), ‘test’)

WebUI.selectOptionByValue(findTestObject(‘Page_/select_Month’), ‘11’, true)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDCVN’), ‘100’)

WebUI.click(findTestObject(‘Page_/span_Pay now’))

WebUI.closeBrowser()

swapna said:

Please help me with this:
Received the following error when I executed automated Test Cases;

Test Cases/Online Order FAILED because (of) Unable to switch to iframe (Root cause: java.lang.NullPointerException)

Error is received in the following line:
WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

Following is the code I have been using:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory

import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘http://giftweb-sit.ad.scentregroup.com/RPortal’)

WebUI.click(findTestObject(‘Page_Buy Westfield Gift Cards Onlin/a_Buy Now’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/button_Add to cart’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/li_50’))

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/div_Go back’))

WebUI.setText(findTestObject(‘Page_Buy Gift Cards Online Westfie/input_Value’), ‘70’)

WebUI.setText(findTestObject(‘Page_Buy Gift Cards Online Westfie/input_Quantity’), ‘1’)

WebUI.click(findTestObject(‘Page_Buy Gift Cards Online Westfie/button_Add to Cart (1)’))

WebUI.click(findTestObject(‘Page_/input_ContactType’))

WebUI.setText(findTestObject(‘Page_/input_ActivationCommunicationT’), ‘swapnareddyj@gmail.com’)

WebUI.setText(findTestObject(‘Page_/input_ActivationCommunicationT_1’), ‘swapnareddyj@gmail.com’)

WebUI.click(findTestObject(‘Page_/button_Proceed to Checkout’))

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.FirstName’), ‘swapna’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.LastName’), ‘reddy’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.StreetAdd’), ‘targo road’)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.Suburb’), ‘girraween’)

WebUI.selectOptionByValue(findTestObject(‘Page_/select_SelectNSWACTNTQLDSATASV’), ‘NSW’, true)

WebUI.setText(findTestObject(‘Page_/input_BillingAddress.PostCode’), ‘2145’)

WebUI.setText(findTestObject(‘Page_/input_EmailAddress’), ‘swapnareddyj@gmail.com’)

WebUI.setText(findTestObject(‘Page_/input_Phone’), ‘123456’)

WebUI.click(findTestObject(‘Page_/span_Next’))

WebUI.click(findTestObject(‘Page_/input_PaymentType’))

WebUI.click(findTestObject(‘Page_/input_AcceptTermsAndConditions’))

WebUI.click(findTestObject(‘Page_/button_Place order’))

WebUI.switchToFrame(findTestObject(‘Page/_ifr_EWAY_CARDNUMBER’), 5)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

WebUI.click(findTestObject(‘Page_/div_id(katalon-elementInfoDiv)’))

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNAME’), ‘test’)

WebUI.selectOptionByValue(findTestObject(‘Page_/select_Month’), ‘11’, true)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDCVN’), ‘100’)

WebUI.click(findTestObject(‘Page_/span_Pay now’))

WebUI.closeBrowser()

Swapna,

When SetText is trying to insert text its failing in iframe…

Go to the object input_EWAY_CARDNUMBER and expand ‘Settings’ and select ‘No’ at ‘Have Parent Object?’

image.png

Thank you Vijay… I tried but error is not fixed.

Could you please let me know if the below code is correct, I am missing someting which i dont knkow:

WebUI.switchToFrame(findTestObject(‘Page/_ifr_EWAY_CARDNUMBER’), 5)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

Test Cases/Online Order FAILED because (of) Unable to set text ‘3777 000000 000000’ of object ‘Object Repository/Page_/input_EWAY_CARDNUMBER’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_/input_EWAY_CARDNUMBER’ located by ‘By.xpath: id(“EWAY_CARDNUMBER”)[count(. | //input[@id = ‘EWAY_CARDNUMBER’ and @name = ‘EWAY_CARDNUMBER’ and @type = ‘tel’ and @placeholder = ‘Card Number’ and @data-validationmessage = ‘Invalid Card Number’ and @class = ‘form-control’ and @autocomplete = ‘off’]) = count(//input[@id = ‘EWAY_CARDNUMBER’ and @name = ‘EWAY_CARDNUMBER’ and @type = ‘tel’ and @placeholder = ‘Card Number’ and @data-validationmessage = ‘Invalid Card Number’ and @class = ‘form-control’ and @autocomplete = ‘off’])]’ not found)

swapna said:

Thank you Vijay… I tried but error is not fixed.

Could you please let me know if the below code is correct, I am missing someting which i dont knkow:

WebUI.switchToFrame(findTestObject(‘Page/_ifr_EWAY_CARDNUMBER’), 5)

WebUI.setText(findTestObject(‘Page_/input_EWAY_CARDNUMBER’), ‘3777 000000 00000’)

Test Cases/Online Order FAILED because (of) Unable to set text ‘3777 000000 000000’ of object ‘Object Repository/Page_/input_EWAY_CARDNUMBER’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_/input_EWAY_CARDNUMBER’ located by ‘By.xpath: id(“EWAY_CARDNUMBER”)[count(. | //input[@id = ‘EWAY_CARDNUMBER’ and @name = ‘EWAY_CARDNUMBER’ and @type = ‘tel’ and @placeholder = ‘Card Number’ and @data-validationmessage = ‘Invalid Card Number’ and @class = ‘form-control’ and @autocomplete = ‘off’]) = count(//input[@id = ‘EWAY_CARDNUMBER’ and @name = ‘EWAY_CARDNUMBER’ and @type = ‘tel’ and @placeholder = ‘Card Number’ and @data-validationmessage = ‘Invalid Card Number’ and @class = ‘form-control’ and @autocomplete = ‘off’])]’ not found)

Is your Iframe dynamic?
Are attributes of Iframe changing every time you open it?
Is iframe id always the same or is it changing every time?
If it is changing then you need to adjust your selector (xpath or CSS).