Search code examples
javaeclipseseleniumselenium-webdriveruser-input

Get user input from IDE/Console in selenium webderiver


I want to get the key(send key) from user input how should I implement it?

driver.findElement(By.xpath(".//*[@id='vehicleNum']")).sendKeys("1121");

in input box what ever user type i want gen then i want to send through selenium?


Solution

  • Even your question is not clear properly but as I am assuming you need below solution. To get the input value from textbox, you can use below code:

     driver.findElement(By.xpath(".//*[@id='vehicleNum']")).sendKeys("1121");
     String str = driver.findElement(By.xpath(".//*[@id='vehicleNum']")).getAttribute("value");
     System.out.println(str);
    

    Program output will be "1121"