WebUiCommonHelper / executeJavaScript: script not running

WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/edit mezzo/Page_C Dettaglio mezzo/span_Salva_btn-label float-left’),30)
WebUI.executeJavaScript(“arguments[0].click”, Arrays.asList(element))

when I run the test the “click” step is skipped and goes to the next step

All that does is reference the click method as a property reference - a bit like saying “is there a click method yes or no?”

ok, got it, but this doesn’t work:

WebUI.executeJavaScript (“arguments [0] .value = ‘Your Value’”, Arrays.asList (element))

what should I put in “your value”?

Please explain “doesn’t work”. Is there an error? Did you check the browser console for errors?

when I run it so doing it WebUI.executeJavaScript (“arguments [0] .value =‘ Your Value ’”, Arrays.asList (element))

the moment of the click is skipped and katalon goes directly to the next step.

what is “your value”?

I need to see…

  1. all the lines of code you’re having trouble with…
  2. the HTML you’re trying to target and…
  3. any errors you receive from Katalon and/or the browser.

html

i’m trying to click this button

button type=“button” name=“save” id=“save” class=“btn waves-effect waves-light btn-block btn-primary text-center” value=“Salva mezzo” xpath=“1”>Salva




this is my script:

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.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.WebElement
import com.kms.katalon.core.webui.common.WebUiCommonHelper

WebUI.callTestCase(findTestCase(‘Self Sender/01. Login’), [:], FailureHandling.STOP_ON_FAILURE)

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Scrivania/span_Mezzi’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Mezzi/button_Nuovo mezzo’))

WebUI.setText(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/input_Targa_vehicle_plate’), ‘2aaasdfgh’)

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/button_Anno del mezzo’))

WebUI.setText(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/anno_mezzo’), ‘2019’)

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/seleziona_data’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/button_Classe mezzo’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/a_Autocarro’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/button_Configurazione mezzo’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/a_Cabinato’))

WebUI.click(findTestObject(‘nuovo mezzo/Page_C Nuovo mezzo/button_Salva’))

WebUI.click(findTestObject(‘edit mezzo/Page_C Mezzi/button_ok’))

WebUI.setText(findTestObject(‘elimna mezzo/Page_C Mezzi/input_Capacit di carico_form-control’), ‘2’)

WebUI.click(findTestObject(‘edit mezzo/Page_C Mezzi/td_2aaasdfgh’))

WebUI.click(findTestObject(‘edit mezzo/Page_C Dettaglio mezzo/button_Nessun driver predefinito’))

WebUI.click(findTestObject(‘edit mezzo/Page_C Dettaglio mezzo/a_demo 102 autista’))

WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/edit mezzo/Page_C Dettaglio mezzo/span_Salva_btn-label float-left’),30)
WebUI.executeJavaScript(“arguments[0].value=‘Your Value’”, Arrays.asList(element))

WebUI.setText(findTestObject(‘elimna mezzo/Page_C Mezzi/input_Capacit di carico_form-control’), ‘2’)

WebUI.click(findTestObject(‘elimna mezzo/Page_C Mezzi/button_Elimina’))

WebUI.click(findTestObject(‘elimna mezzo/Page_C Mezzi/button_OK’))




i have some problems with this part of the script

WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/edit mezzo/Page_CargUp Dettaglio mezzo/span_Salva_btn-label float-left’),30)
WebUI.executeJavaScript(“arguments[0].value=‘Yout Value’”, Arrays.asList(element))




katalon doesn’t return me an error, but the moment of the click is skipped and katalon goes directly to the next step.

Try this.

/*
WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/edit mezzo/Page_C Dettaglio mezzo/span_Salva_btn-label float-left’),30)
WebUI.executeJavaScript(“arguments[0].value=‘Your Value’”, Arrays.asList(element))
*/
String js = 'document.querySelector("#save").click();'
WebUI.executeJavaScript(js, null);

If it doesn’t work, I need to see a lot more HTML.

1 Like

now works! I don’t know how to thank you, magnificent! thank you so much

1 Like