Can Katalon Test SAP HTML with FRAMESETs? [was: How to extract value of a text field?]

I concur. SAP HTML is the worst possible thing to test. They should be hung from the rafters for using DEPRECATED framesets (nested too!) and all manner of idiotic contrivances designed to obfuscate and confuse. Not only that, they’re using cross-origin iframe sources making it very difficult to debug using industry standard tools like DevTools.

Sorry, @saumil.sah, but I don’t have time to waste on this mess. I pity you having to work with crap like this – you deserve and have my sympathy.

Take this thread and show it to your manager. Tell him to show it to his manager. And if they blame Katalon and tell you to look for something else, tell them I didn’t use Katalon, I used a BROWSER and DEVTOOLS. I wouldn’t even try to use Katalon until a browser and DevTools can make sense of it.

I wanted to clarify why my code does not work.

I made another Test Case

By a study backed by the TC3, I believe I have found out a fact.

I could not grasp a DOM node of <FRAMESET>, <FRAME> and whole descendant nodes.

@saumil.sah You could use Selenium code directly (it seems) but there’s a huge caveat to doing that.

If you know ahead of time that the page is built using broken, non-standard, deprecated elements, what will you do if your test passes?

If you say “it’s a pass!”, you’re lying. It’s NOT A PASS. The page is broken from the get go.

What will you do if it’s a fail? Well, you knew it was a fail even before you ran the test!

So, BE WARNED.

With that said, take a look here:

Disclaimer: I cannot vouch for any of that code.

@Russ_Thomas

Thank you for your input.

I tried to learn the link you provided and tried to find a solution for the original post, but I couldn’t after a few hours of struggle. Well, it is too difficult and tiresome for me to test a HTML with FRAMESET.

@kazurayam,

I try with this xpath and I see it works

(//td/div/span/label[normalize-space(.) = ‘ID:’]/parent::span/parent::div/parent::td/following-sibling::td[@class=‘ch-grid-cell’])//span"

If you want to get value of ID: column, using text as ‘ID:’
If you want to get value of Description, change xpath, replace ‘ID:’ by ‘Description:’

FYI

@loc.nguyen

How did you write WebUI.switchToFrame() stuff?

Thank you for your input.

You tried that xpath in the console tab of Chrome’s DevTools with $x() function, and you wrote “it works”.

I am afraid your post does not answer to the original poster @saumil.sah. He asked how to write a Test Case script in Katalon Studio to test the SAP HTML. He did not ask us how to write $x() function in the DevTool console. These are 2 different problems.

When I tried to write a Test Case, I found a difficulty for “WebUI.switchToFrame()” for <FRAMESET> tags.

When you interacted with the DevTools console, you manually did operation equivalent to “WebUI.switchToFrame()”. It seems that your view point in the DevTool successfully passed the wall of <FRAMESET> and you could reach to the target HTML document. Then you applied $x() function and found it works. Ok, it’s nice to know this. But $x() in the DevTool doesn’t solve the problem of original post.

H @kazurayam,

I did not try with switch IFrame but I think that the solution is the same. We have a document to get Selenium Web Driver: https://docs.katalon.com/katalon-studio/docs/using_selenium_webdriver_katalon_studio.html#options-and-capabilities

Original driver can switch the IFrame so I guess that we can switch to them, then we can continue to find the xpath. On previous comment of @saumil.sah “The id generated is a dynamic value which needs to be captured everytime the script is getting executed”, I saw some comment related to this dynamic object

Reference link: https://www.guru99.com/handling-iframes-selenium.html

FYI.

OK.

Please try with switching into FRAMESET by WebUI.switchToFrame() keyword or WebDriver.switchTo().frame(id)

I did try it and failed.

I think that the solution is, surprisingly, not the same as IFrame. At least, not as simple as users expect.

As @Russ_Thomas pointed out, <FRAMESET> has been depreceted and not supported in HTML5. I would not be surprised to find any curiosities about FRAMESET.

Hi @kazurayam,

Please try with script below:

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver

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

WebUI.openBrowser(‘file:///C:/Users/loc.nguyen/Downloads/Test/Unified%20Lead_%20201481098,%20TA_UL_FU_OPP_HARMONY_ME_DIRECT,%20Test%20Company%20RD.05%20-%20[SAP].mhtml’) //Change to your file path
WebUI.delay(1)
WebDriver myDriver = DriverFactory.getWebDriver()

iframe1 = myDriver.findElement(By.id(“CRMApplicationFrame”))
myDriver.switchTo().frame(iframe1)

frameset1 = myDriver.findElement(By.tagName(“frameset”))
c = frameset1.getAttribute(“rows”)

content = frameset1.findElement(By.id(“contentFrameset”))
d = content.getAttribute(“rows”)

frame1Next = content.findElement(By.id(“WorkAreaFrame1”))
e= frame1Next.getAttribute(“name”)

myDriver.switchTo().frame(frame1Next)
println e

After executing, I am able to see the attribute of last frame that means we have just by passed the FRAMESET. The ide here is Selenium not support switch FRAMESET but we can identify it by tag then switch to its frame

Now, we resolve the FRAMESET problems, please try with remaining frame (same approach)

FYI.

@loc.nguyen

Thank you. I studied you code and finally got a solution to the original post:

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

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

File html = new File("Unified Lead_ 201481098, TA_UL_FU_OPP_HARMONY_ME_DIRECT, Test Company RD.05 - [SAP].mhtml")
URL url = html.toURI().toURL();
WebUI.openBrowser(url.toExternalForm());
WebUI.delay(1)
WebDriver myDriver = DriverFactory.getWebDriver()

CRMApplicationFrame = myDriver.findElement(By.id("CRMApplicationFrame"))
myDriver.switchTo().frame(CRMApplicationFrame)

WorkAreaFrame1 = myDriver.findElement(By.id("WorkAreaFrame1"))
myDriver.switchTo().frame(WorkAreaFrame1)

WebElement el = myDriver.findElement(By.xpath("//td/div/span/label[normalize-space(.) = 'ID:']/parent::span/parent::div/parent::td/following-sibling::td[1]//span"))
String val = el.getText()

println val    // => 201481098

myDriver.quit()

From you code, I learned that

  1. we need to switchToFraome() to <iframe> and <frame>
  2. but we do not need to call switchToFrame() to <FRAMESET> at all
2 Likes

The following code uses WebUI keywords only, does not use Selenium WebDriver API directly, does the same processing.

import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

File html = new File("Unified Lead_ 201481098, TA_UL_FU_OPP_HARMONY_ME_DIRECT, Test Company RD.05 - [SAP].mhtml")
URL url = html.toURI().toURL();
WebUI.openBrowser(url.toExternalForm());

WebUI.switchToFrame(makeTO("//*[@id='CRMApplicationFrame']"), 5)

WebUI.switchToFrame(makeTO("//*[@id='WorkAreaFrame1']"), 5)

TestObject to = makeTO("//td/div/span/label[normalize-space(.) = 'ID:']/parent::span/parent::div/parent::td/following-sibling::td[1]//span")
String val = WebUI.getText(to)

println val

WebUI.closeBrowser();

TestObject makeTO(String expr) {
	TestObject to = new TestObject(expr);
	to.addProperty("xpath", ConditionType.EQUALS, expr)
	return to
}

Tried your code, this is the error I get:

I confirmed that my code works:

That’s all I can say.

You wrote you got an error. If so, your code must be somehow different from my code, or your Application Under Test is somewhat different form the MHTML you provided to us. But I can not see what.

1 Like

Hi @kazurayam! The solution works. Had to make a small tweak, wherein had to close the browser and open it again and navigate to the page via some other channel! Really a pain to capture things in this HTML layout.

Thanks to other members here as well for giving their thoughtful insights! Hands down the best community out there :smiley:

1 Like