Switchto.frame does not work, it opens a new browser instead?

Hi team,

I used the switchto.frame function as my my web application has multiple frames. It sees the object so it means it works. However, when I run it, it opens another tab or browser instead of switching to a particular frame. Is it a bug?

Anyone? Here’s my code:

//‘Switch to iframe’

WebUI.switchToFrame(findTestObject(‘Main page/BANNERSECTION frame’), 1)
WebUI.click(findTestObject(‘Main page/Company RDA link’))

Any moderator out here? Still a problem for me.

Sorry for the late response. What was the expected behavior for WebUI.click(findTestObject(‘Main page/Company RDA link’))?

Hi Alex, Thanks for taking time to look into this matter.

The objective is to switch to the right frame then click the weblink button inside that frame.

The xpath of Object repository “Company RDA link” is //*[@id=“pane_”]/div[1]/div/table/tbody/tr/td[7]/a (No Parent object and it seems it is found as no error is encountered. However, it opens a new window instead).

I use IE as the browser.

Our web app has multiple frames. Unfortunately, it is only accessible via our internal server so I can’t share the URL.

Full script:
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

WebUI.waitForPageLoad(2)

//‘Switch to iframe’

WebUI.switchToFrame(findTestObject(‘Main page/BANNERSECTION frame’), 1)

WebUI.click(findTestObject(‘Main page/Company RDA link’))

WebUI.waitForPageLoad(3)

So the link will open inside the frame when it is clicked manually, but with Selenium, a new window will open - is it correct?

HI,Evan,
If you’ve already jumped to another frame before you jump to this one(BANNERSECTION frame), you need to jump to the default frame and then to the target frame.as follows:

WebUI.switchToDefaultContent()WebUI.switchToFrame(findTestObject('Main page/BANNERSECTION frame'), 1)WebUI.click(findTestObject('Main page/Company RDA link'))

hope this helps

Alex said:

So the link will open inside the frame when it is clicked manually, but with Selenium, a new window will open - is it correct?

One window (web screen) will have multiple frames. Let’s say frame zero will contain the “RDA Link”. If done manually, I just need to click the link.
In Selenium webdriver, I use switchto().frame(BANNERSECTION) then click the link and it opens a new tab (this is correct).
If using the script in Katalon, I switch to the frame first (BANNERSECTION frame) then click the link and it seems that it goes back to the first test case where the URL is entered in the log on screen (this is not correct).

My test suite consists of two test cases:
1. Log on to the environment
2. Create new customer (this is where I try to click the RDA Link and it opens a new window and inserts the URL entered in “Test case 1. Log on to the environment” instead).

See script below for “Test case 1. Log on to the environment”:

def data = findTestData(‘Logon’)

for (def index : (1…data.getRowNumbers())) {

WebUI.openBrowser(data.getValue('Environment', index))



WebUI.setText(findTestObject('Log in page/Username input'), data.getValue('Username', index))



WebUI.setText(findTestObject('Log in page/Password input'), data.getValue('Password', index))



WebUI.click(findTestObject('Log in page/Sign In button'))

}

Monster said:

HI,Evan,
If you’ve already jumped to another frame before you jump to this one(BANNERSECTION frame), you need to jump to the default frame and then to the target frame.as follows:

WebUI.switchToDefaultContent()WebUI.switchToFrame(findTestObject('Main page/BANNERSECTION frame'), 1)WebUI.click(findTestObject('Main page/Company RDA link'))

hope this helps

Hi Monster,

Thanks. I tried to includeswitchToDefaultContent but same result.
Also, it seems that it is in the correct frame as the web element is located: _Found 1 web elements with id: ‘Object Repository/Main page/Company RDA link’ located by 'By.xpath
_
Only when the object is “Clicked” that it opens a new window with the URL indicated as per the script above.

Cheers,
Evan

HI,Evan,

There’s a way you can try it.

But this way doesn’t seem very strict to software test engineers.

You don’t have to click on that Object to jump to the URL you want.

Find out the target URL you need to jump to.

then,do it like this:

WebUI.navigateToUrl('The URL  U want to open')


Monster said:

HI,Evan,

There’s a way you can try it.

But this way doesn’t seem very strict to software test engineers.

You don’t have to click on that Object to jump to the URL you want.

Find out the target URL you need to jump to.

then,do it like this:

WebUI.navigateToUrl('The URL  U want to open')

You’ve got a good point there. However, the “link” does not have a unique URL. I am not familiar with the behaviour of internal web application but it seems that when the link is clicked, same URL appears (http:///BrowserWeb/servlet/BrowserServlet) as when I logged on. Hovering on the link will show javascript.void(0).

Alex, Monster, anyone?

Evan said:

Alex said:

So the link will open inside the frame when it is clicked manually, but with Selenium, a new window will open - is it correct?

One window (web screen) will have multiple frames. Let’s say frame zero will contain the “RDA Link”. If done manually, I just need to click the link.
In Selenium webdriver, I use switchto().frame(BANNERSECTION) then click the link and it opens a new tab (this is correct).
If using the script in Katalon, I switch to the frame first (BANNERSECTION frame) then click the link and it seems that it goes back to the first test case where the URL is entered in the log on screen (this is not correct).

My test suite consists of two test cases:
1. Log on to the environment
2. Create new customer (this is where I try to click the RDA Link and it opens a new window and inserts the URL entered in “Test case 1. Log on to the environment” instead).

See script below for “Test case 1. Log on to the environment”:

def data = findTestData(‘Logon’)

for (def index : (1…data.getRowNumbers())) {

WebUI.openBrowser(data.getValue('Environment', index))



WebUI.setText(findTestObject('Log in page/Username input'), data.getValue('Username', index))



WebUI.setText(findTestObject('Log in page/Password input'), data.getValue('Password', index))



WebUI.click(findTestObject('Log in page/Sign In button'))

}

HI Evan,

Looks like you have two test cases here. I went through whole post but still can you put both the test cases script one after another. Let me see if I can help you with this.

Hi Vijay,

This is my first test case:

def data = findTestData('Logon')
for (def index : (1..data.getRowNumbers())) {
    WebUI.openBrowser(data.getValue('Environment', index))
    WebUI.setText(findTestObject('Log in page/Username input'), data.getValue('Username', index))
    WebUI.setText(findTestObject('Log in page/Password input'), data.getValue('Password', index))
    WebUI.click(findTestObject('Log in page/Sign In button'))
}

This is my 2nd test case:

WebUI.waitForPageLoad(2)
WebUI.switchToDefaultContent()
//'Switch to iframe'
WebUI.switchToFrame(findTestObject('Main page/BANNERSECTION frame'), 1)
WebUI.click(findTestObject('Main page/Company RDA link'))
WebUI.waitForPageLoad(3)

So it seems like after clicking “Main page/Company RDA link”, it goes back to first test case and just opens the URL link and stop. No errors.

It would be nice to have someone help me on this issue? Katalon looks really promising so I want to make this work and introduce to my company. However, it seems I will get stuck on this functionality.

Do you have any recording video about this case?

Or is it possible to send me your project in this case if your web application can be accessed from outside?

Regards

Evan,

It is a little bit hard to see the test case flow in your cases. Generally, switchToFrame() built-in function of Katalon Studio and Selenium having the same behavior: move the test context to the frame. These function will not open any frames, or tabs, or browsers. So it might not the case.

Your 1st test case scripts might have unexpected behaviors because a browser is opened for each row in your ‘Logon’ test data without being closed. I would suggest that you create a simple login test case and execute it with data-driven approach at test suite level.

Your 2nd test case seems not correct. The correct flow for working with frames is:
- Some actions to open the new frame or the frame already existed.
- Switch to the above frame
- Do something in the switched frame
- Switch back to the default content

It would be a great help if you could provide a video showing your test flow and what did you do to handle the case.

Vinh Nguyen said:

Or is it possible to send me your project in this case if your web application can be accessed from outside?

Regards

Unfortunately, I am unable to upload videos due to company restriction. It is also an internal web application that cant be accessed outside. However, I will try to find alternative ways to provide more details.

Trong Bui said:

Evan,

It is a little bit hard to see the test case flow in your cases. Generally, switchToFrame() built-in function of Katalon Studio and Selenium having the same behavior: move the test context to the frame. These function will not open any frames, or tabs, or browsers. So it might not the case.

Your 1st test case scripts might have unexpected behaviors because a browser is opened for each row in your ‘Logon’ test data without being closed. I would suggest that you create a simple login test case and execute it with data-driven approach at test suite level.

Your 2nd test case seems not correct. The correct flow for working with frames is:
- Some actions to open the new frame or the frame already existed.
- Switch to the above frame
- Do something in the switched frame
- Switch back to the default content

It would be a great help if you could provide a video showing your test flow and what did you do to handle the case.

I just added the “switch back to default content” as a 2nd step since nothing is working. I tried to switch back as the 4th step as per your suggestion above but still same results.
I will try to provide further details as there are heaps of company restriction.