# Selenium code with -\> throws error in Katalon

**URL:** <https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [March 20, 2019, 2:30pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587 "2019-03-20T14:30:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![focis.automation](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@focis.automation](https://forum.katalon.com/u/focis.automation)\
**Post date:** [March 20, 2019, 2:30pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/1 "2019-03-20T14:30:05Z")

</div>

Hi …

I am trying create a custom keyword using selenium java code … but this **→** symbol is not recognized in katalon. Kindly help …

```auto
 public static void angularLoads(String angularReadyScript) {
 		try {
 			System.err.println("1")
 			
 			WebDriver driver = DriverFactory.getWebDriver();
 			
 			ExpectedCondition<Boolean> angularLoad = driver -> Boolean.valueOf(((JavascriptExecutor) driver)
 				.executeScript(angularReadyScript).toString());} 
 catch (WebDriverException ignored) {
 		
 		System.err.println("CATCh")
 		}
 	}

```

 ![Error](https://europe1.discourse-cdn.com/katalon/original/2X/0/0f8dca32369920f741d0ef7fbc794c84bf1c52ac.jpeg)

The purpose of this keyword is for Angular waits.

> **[Selenium Webdriver wait for JavaScript JQuery and Angular](https://swtestacademy.com/selenium-wait-javascript-angular-ajax/)**
>
> Wait JQuery, Angular and JavaScript calls in your Selenium Webdriver test codes with a significantly stable solution without sleep() statements.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 20, 2019, 2:42pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/2 "2019-03-20T14:42:58Z")

</div>

Confirmed. I just tried the jQuery example - same issue. I’m moving this to the Bugs category.

By the way, by creating this as a custom keyword, you’re recreating what Katalon’s WebUI APIs already do.

---

<div class="post-metadata">

**Author:** ![focis.automation](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@focis.automation](https://forum.katalon.com/u/focis.automation)\
**Post date:** [March 21, 2019, 11:19am UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/3 "2019-03-21T11:19:35Z")

</div>

Hi Russ, FYI … The built in keyword **WebUI.waitForAngularLoad(10) ;** doesn’t work.

Kindly run the below script in chrome browser.

> WebUI.openBrowser(‘[https://angular.io/](https://angular.io/)’)
> 
> WebUI.waitForAngularLoad(10)

> 2019-03-21 16:22:42.617 **WARN** c.k.k.c.w.k.b.WaitForAngularLoadKeyword **This page doesn’t use Angular.**

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 21, 2019, 12:35pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/4 "2019-03-21T12:35:02Z")

</div>

Wow. That’s bad.

Okay, point noted. But let’s focus on the main topic: **-\>** is legal in Groovy, and copying the code from the Se example should work.

@YoungNgo @devalex88 @ThanhTo can you guys take a look please?

---

<div class="post-metadata">

**Author:** ![devalex88](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/devalex88/32/336_2.png) [@devalex88](https://forum.katalon.com/u/devalex88)\
**Post date:** [March 21, 2019, 1:13pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/5 "2019-03-21T13:13:52Z")

</div>

Actually in Groovy the closure syntax is `{a -> code block}` compared to Java’s lambda one `a -> code block`.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 21, 2019, 1:17pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/6 "2019-03-21T13:17:24Z")

</div>

I thought braces were optional in that scenario. Oh well. Thanks Alex.

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/7/704fc8077ad3e66be7237058065b647774de97cc.png)

Yep. _Not_ optional.

> **[The Apache Groovy programming language - Closures](http://groovy-lang.org/closures.html)**

---

<div class="post-metadata">

**Author:** ![focis.automation](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@focis.automation](https://forum.katalon.com/u/focis.automation)\
**Post date:** [March 21, 2019, 6:33pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/8 "2019-03-21T18:33:52Z")

</div>

@Russ_Thomas

Thanks …

When using the below keyword getting null pointer exception, Could you please help me …

 ![Ang](https://europe1.discourse-cdn.com/katalon/original/2X/6/6c984630228dc4eed17fc9db97ecb29720851bda.jpeg)

> @Keyword  
> public static void angularLoads() {  
> try {
> 
> ```
> driver = DriverFactory.getWebDriver();
>   				
> String angularReadyScript = 'return window.getAllAngularTestabilities().findIndex(x=>!x.isStable()) === -1';
>   	
> 
> ExpectedCondition<Boolean> angularLoad = { driver -> } Boolean.valueOf(((JavascriptExecutor) driver)
> .executeScript(angularReadyScript).toString());
> 
> boolean angularReady = Boolean.valueOf(((JavascriptExecutor) driver).executeScript(angularReadyScript).toString());
> 
> if (!angularReady) {
> 
> new WebDriverWait(driver, 10).until(angularLoad); // this is failing -null pointer
>   		
> }
> } catch (WebDriverException ignored) {
> }
> 
> ```
> 
> }//

 ![An1](https://europe1.discourse-cdn.com/katalon/original/2X/e/eb83649111a745a9fae0050ff07aa3ede5dda643.jpeg)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [March 21, 2019, 6:56pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/9 "2019-03-21T18:56:22Z")

</div>

I’m really not familiar with the pattern you’re aiming for but I can see syntax errors.

Why don’t you follow the patterns @Brandon_Hein gave you in this thread?

> [@Wait commands doesn't wait enough time](http://forum.katalon.com/t/wait-commands-doesnt-wait-enough-time/16875/13):
>
> Hi Brandon, Could you please tell … How to use this in Katalon and the imports required --\> Using @Keyword. Thanks.

---

<div class="post-metadata">

**Author:** ![focis.automation](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@focis.automation](https://forum.katalon.com/u/focis.automation)\
**Post date:** [March 21, 2019, 7:15pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/10 "2019-03-21T19:15:29Z")

</div>

Thanks Russ …

@Brandon_Hein …Any help on this is highly appreciated.

I am trying to create custom keyword for the latest Angular application, below is the link, I am interested on the below methods mentioned in the link.

**waitUntilAngular5Ready();**  
**private void waitForAngular5Load()**  
**private void angularLoads(String angularReadyScript)**

> **[Selenium Webdriver wait for JavaScript JQuery and Angular](https://swtestacademy.com/selenium-wait-javascript-angular-ajax/)**
>
> Wait JQuery, Angular and JavaScript calls in your Selenium Webdriver test codes with a significantly stable solution without sleep() statements.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [March 21, 2019, 7:43pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/11 "2019-03-21T19:43:34Z")

</div>

As @Russ_Thomas pointed out, you can (probably) use the same format that I used for checking jQuery conditions in the linked topic. For example, just take the javascript from your angularLoads() method and put it in the relevant place (in the js.executeScript() call):

```
public static void angularLoads() {
		new WebDriverWait(DriverFactory.getWebDriver(), 300, 100).until(new ExpectedCondition<Boolean>() {
					@Override
					public Boolean apply(WebDriver d) {
						JavascriptExecutor js = (JavascriptExecutor)d;
						return (Boolean)js.executeScript(
								"return window.getAllAngularTestabilities().findIndex(x=>!x.isStable()) === -1");
					}
				});
}
```

---

<div class="post-metadata">

**Author:** ![focis.automation](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@focis.automation](https://forum.katalon.com/u/focis.automation)\
**Post date:** [March 22, 2019, 12:44pm UTC](https://forum.katalon.com/t/selenium-code-with-throws-error-in-katalon/21587/12 "2019-03-22T12:44:27Z")

</div>

Thanks Brandon.
