Sagar
Sagar

Reputation: 31

The method sendkeys(int) is undefined for the type WebElement

I am using below code to give date as input:

Selecting Journey Date 
WebElement journeydate  = driver.findElement(By.xpath("//select[@name='lccp_day']")).sendkeys(20);

I believe issue is because of sendkeys is not accepting integers.

Please give suggestion what else I can use to give input as integers for any text box.

Using JAVA Compiler 1.8 and Firefox version 42.

Upvotes: 0

Views: 2345

Answers (3)

Shubham Jain
Shubham Jain

Reputation: 17553

SendKeys Function accepts only string. so you need to type case your int to string before passing it to Senkeys.

Nick has shown you one way.

You can also perform same like below :-

     int i=0;
     String j = Integer.toString(i);
     driver.findElement(By.name("q")).sendKeys(j);

OR

     Integer obj = new Integer(i);
     String str4 = obj.toString();
     driver.findElement(By.name("q")).sendKeys(str4);

OR

     String str5 = new Integer(i).toString();
     driver.findElement(By.name("q")).sendKeys(str5);

OR

     String str6 = new Integer(1234).toString();
     driver.findElement(By.name("q")).sendKeys(str6);

Hope it will help you :)

Upvotes: 0

iamsankalp89
iamsankalp89

Reputation: 4739

Instead of this

//Selecting Journey Date 
WebElement journeydate = driver.findElement(By.xpath("//select[@name='lccp_day']")).sendkeys(20);

use this

//Selecting Journey Date 
WebElement journeydate = driver.findElement(By.xpath("//select[@name='lccp_day']")).sendkeys("20");

Upvotes: 0

Nickname
Nickname

Reputation: 115

You could use

String.valueOf(20);

to add your integer value as a String. And yes, judging by the documentation sendKeys only accepts CharSequences.

Upvotes: 1

Related Questions