Whenever I try to execute a script with functions that have multiple parameters, I keep getting an error:
Exception in thread "main" org.openqa.selenium.JavascriptException: ReferenceError: coords is not defined
This is my script:
enter code here
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("setNewCellType(new ZmianaTypuCommandFactory(),currentRozdzial,currentTable,this.activeCoords)");
I found the functions in the developer's tools and their format is:
function setNewCellType(factory,nrRozdzial,tab,coords,newState,mode)
I set a breakpoint at this point to retrieve the parameters, and the parameters are:
setNewCellType(newZmianaTypuCommandFactory(),currentRozdzial,currentTable,this.activeCoords,params);
this.activeCoords have value
(col: 2
colspan: 1
row: 2
rowspan: 1
siatkaCol: 2
siatkaRow: 2)
Can someone help me resolve this issue?
The element I am trying to use has a dynamic value, which changes during each session.
Additional scripts:
driver.findElement(By.id("addTableRowCount")).clear();
driver.findElement(By.id("addTableRowCount")).sendKeys("9");
driver.findElement(By.id("addTableColCount")).clear();
driver.findElement(By.id("addTableColCount")).sendKeys("2");
driver.findElement(By.id("addTableOK")).click();
driver.switchTo().defaultContent();
driver.findElement(By.id("tytulTabeli")).sendKeys("Tytuł tabeli - 1");
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//p[text()='Obszar danych']")));
driver.findElement(By.xpath("//p[text()='Obszar danych']")).click();
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver)
.executeScript("setNewCellType(new ZmianaTypuCommandFactory(),currentRozdzial,currentTable,this.activeCoords)");
@Zhivko.Kostadinov
var ZmianaTypuCommandFactory = Class.create(CellTypeChangeCommandFactory,{
initialize: function($super){
$super(new ZmianaTypuValidator());
this.wymagalnoscFactory = new WymagalnoscCommandFactory();
},
createSingleCmd: function(nrRozdzial,tab,coords,newState){
if(newState.cellType.cellTypeInt == TYPY_KOMOREK.ZAZNACZENIE.cellTypeInt)
{ var cmd = new CompositeCommand();
var typeCmd = new ZmianaTypuCommand();
typeCmd.setState(tab,coords,newState);
cmd.addCommand(typeCmd);
var wymagalnoscCmd = this.wymagalnoscFactory.createCmd(nrRozdzial,tab,coords,true);
if(wymagalnoscCmd){
cmd.addCommand(wymagalnoscCmd);
return cmd;
}
else{
return typeCmd;}}
else{
var cmd = new ZmianaTypuCommand();
cmd.setState(tab,coords,newState);
return cmd; }}});