Selenium Error: sendKeys command not working properly. Can anyone resolve it?

Viewed 29

I am trying to automate a site which asks the person about his details. In the Name of Applicant field we are supposed to write the full name.So clearly name contains first name and last name and there must be space between first name and last name. But when I am trying to send the name using sendKeys command the characters after space (i.e last name) is not being sent and instead a lot of whitespaces are coming. I cant figure out the problem. Please, any help would be appreciated.

**Here is my code which I have written in eclipse IDE: **

package automation;

import java.time.Duration;

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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class residence {

public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub
    System.setProperty("webdriver.chrome.driver", ".\\lib\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    /*Store the current window handle */
    String parent_handle = driver.getWindowHandle();
    driver.get("https://serviceonline.bihar.gov.in/resources/homePage/10/loginEnglish.htm");
    driver.findElement(By.xpath("//label[contains(text(),'General')]")).click();
    driver.findElement(By.xpath(("//p[contains(text(),'Residential')]"))).click();
    driver.findElement(By.xpath(("//div[@id='collapseOneOne']/div/p/a"))).click();
    
    for(String winHandle:driver.getWindowHandles()){
        if(!parent_handle.equals(winHandle))
            driver.switchTo().window(winHandle);
    }
    
    /* Write Gender accordingly.Default is Male(M).(F) and (T)*/
    char gender='M';
    WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds(30));
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[@for='17290_1']/input")));
    if(gender=='M')
    {
        driver.findElement(By.xpath("//input[@id='17290_1']")).click();
    }
    else if(gender=='F')
    {
        driver.findElement(By.xpath("//input[@id='17290_2']")).click();
    }
    else
    {
        driver.findElement(By.xpath("//input[@id='17290_3']")).click();
    }
    
    WebElement obj=driver.findElement(By.xpath("//input[@name='78250']"));
    
    /* I have also tried obj.sendKeys("Sumit Kumar") , this is also not working*/
    
    obj.clear();
    obj.sendKeys("Sumit",Keys.SPACE,"Kumar");
    obj = driver.findElement(By.xpath("//input[@name='17287']"));
    obj.clear();
    obj.sendKeys("Name in Hindi with space ");
}  

}  

Here, are my screenshots of output:

Error image

Note:- Please note that it works in the adjacent text box as expected.

0 Answers
Related