Seeing issues in automating Google Calculator | Selenium Forum
M
Posted on 05/12/2016
Hello team,

I am trying to do calculator exercise today and unable to write the string values of numbers in text field from excel sheet

Please see my code below and if possible can you please send me the solution to that exercise. I tried several logics but none of them worked.

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.JavascriptExecutor;


public class seventh {

static WebDriver driver = null;

@Test(dataProvider = "getdata")
public static void Calculator(String num1,String operation, String num2) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Desktop\\jar files\\chromedriver_win32\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("https://www.google.ca/");
driver.findElement(By.id("lst-ib")).sendKeys("CALCULATOR");
driver.findElement(By.id("lst-ib")).sendKeys(Keys.ENTER);
Thread.sleep(8000);
// String strJavaScript = "document.getElementById('cwos').textContent= " + num1.trim() + " " + operation.trim() + " " + num2.trim() ;
Thread.sleep(8000);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("document.getElementById('cwos').value = '123';");

}



@DataProvider
public Object[][] getdata(){
Xls_Reader xls = new Xls_Reader("E:\\Calculator.xlsx");
int Columns = xls.getColumnCount("Addition");
int Rows = xls.getRowCount("Addition");
Object[][] data = new Object[Rows-1][Columns-3];
for(int rNum=2;rNum<=Rows;rNum++){
for(int cNum=0;cNum<Columns-3;cNum++){
data[rNum-2][cNum] = xls.getCellData("Addition", cNum, rNum);
System.out.println(data[rNum-2][cNum]);
}
}
return data;
}
}

M
Replied on 09/12/2016

What is error


M
Replied on 09/12/2016

There is no error but I am unable to see the numbers displayed in the text box displayed for calculator. I almost got the logic from one of the previous post by someone else and I tried that code as well but it is not working for me and I don't see the numbers displayed in text box when I run that script.