How can I write javascript on Katalon tool?

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

Sometimes, I've met the element which is unable to click with the normal script by selenium so I have to use javascript to execute my script.

回答1:

((JavascriptExecutor) DriverFactory.webDriver).executeScript('Your JavaScript-Code', argument);


回答2:

I believe you mean, Executng the Javascript code and get the element. You can try this appraoch - https://docs.katalon.com/display/KD/%5BWebUI%5D+Execute+JavaScript



回答3:

You can try using a custom keyword, inside of the package "yourPackage":

@Keyword static clickJS (TestObject to, int timeout) {     WebUI.waitForElementVisible(to, timeout)     try {         WebUI.click(to)     }     catch (Exception e) {         WebDriver driver = DriverFactory.getWebDriver()         WebElement element = WebUiCommonHelper.findWebElement(to, timeout)         JavascriptExecutor executor = ((driver) as JavascriptExecutor)         executor.executeScript('arguments[0].click()', element)     }     throw(e) }

Then, you can call the function inside your test script with:

CustomKeyords.'yourPackage.yourClass.clickJS'(findTestObject("yourObject"))


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!