Two iframes over one button

Hello guys,

I need to make an automate test for a game, the first part was really easy (open browser, navigate to, log in, launch the game). The problem is that after I have launched the game I need to click one button which is covered by 2 iframes.

First iframe is class = “iframe” , the second is class = “game-client-iframe” and the button is class = “column right”.

I’m not sure that I know how to do this…

WebUI.switchToFrame(findTestObject(``'PPAndrei/iframe'``), ``50````) WebUI.switchToFrame(findTestObject('PPAndrei/game-client-iframe'), 50)
`WebUI.waitForElementVisible(findTestObject(‘PPAndrei/Click_Button’), 50)
WebUI.click(findTestObject(‘PPAndrei/Click_Button’)

Can someone help?
Thank you,
Andrei

I’m not sure why you have switch to frame twice, but you are not doing anything on those frames. As far as not being able to click, I have run into this before and use a custom keyword to click using javascript. Maybe try this? Hopefully it helps.

just create a custom key word with the below.

_____________________________________________________________________

public class JavascriptClick {

@Keyword

def clickUsingJS(TestObject to) {

WebDriver driver = DriverFactory.getWebDriver()

WebElement element = WebUiCommonHelper.findWebElement(to, 30)

JavascriptExecutor executor = ((driver) as JavascriptExecutor)

executor.executeScript(‘arguments[0].click()’, element)

}

}

_________________________________________________________________

use would be:
CustomKeywords.‘customKeywordsFromKatalon.JavascriptClick.clickUsingJS’(findTestObject(‘PPAndrei/Click_Button’))

your script might be different based upon the package name you give your keyword.

Hi @B L

I have tried what you told me, and I receive the following error…

**Verification FAILED because (of) Variable ‘DriverFactory’ is not defined for test case.

**I have this in my console…

package pachetnou

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.annotation.Keyword

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

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

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

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

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

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

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

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

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

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

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

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

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.JavascriptExecutor;

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile

import WSBuiltInKeywords as WS

import WebUiBuiltInKeywords as WebUI

public class doamneajuta {

@Keyword

def clickUsingJS(TestObject to) {

WebDriver driver = DriverFactory.getWebDriver()

WebElement element = WebUiCommonHelper.findWebElement(to, 30)

JavascriptExecutor executor = ((driver) as JavascriptExecutor)

executor.executeScript(‘arguments[0].click()’, element)

}

}

any ideas? thank you

hello again,

I have found the problem, “def” was missing from def WebDriver driver = DriverFactory.getWebDriver()…

My issue now is that the tool is not finding my object…

‘PPAndrei/BaraIframe’ located by 'By.cssSelector: css=#button ’ not found

What is wrong now because I don’t understand

looks like an issue with the css for that object. maybe try xpath to identify the object?

I assume that when you say:

… you mean that it’s nested within two frames, i.e. the button exists within an iframe that also has a parent iframe:

<iframe class="iframe">
    <iframe class="game-client-iframe">
        <button class="column right">
        ...
        </button>
    </iframe>
</iframe>

You have the right approach. You will need to do two frame switches:

WebUI.switchToFrame(findTestObject('PPandrei/iframe'), 30);
WebUI.switchToFrame(findTestObject('PPAndrei/game-client-iframe'), 30);
.
.
.

Don’t bother with the JavaScript approach, it will not help you here.

Now I’m confused, because in your OP, you made no mention of ‘PPAndrei/BaraIframe’. Can you provide a screenshot of the HTML that you’re working with, which includes both iframes as well as the target button? Also, can you provide screenshots of the Test Objects that you have defined to locate all three of those things (the two frames and the button). This will help us provide you with appropriate locators/test code. Thanks.

1 Like