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"))