Reputation: 11
Here is my code:
WebElement firstname = driver.findElement(By.name("firstname"));
firstname.sendKeys("X");
WebElement lastname = driver.findElement(By.name("lastname"));
lastname.sendKeys("Y");
System.out.println(firstname lastname); // ???
Upvotes: 1
Views: 83
Reputation: 106
If you want to print two WebElement you can use your code in the below format:
WebElement firstname = driver.findElement(By.name("firstname"));
firstname.sendKeys("X");
WebElement lastname = driver.findElement(By.name("lastname"));
lastname.sendKeys("Y");
System.out.println(firstname + "--------" + lastname);
However you will get only nonsense value which is of no use. Your output will be the String representation of WebElement. Can you please let me know what you are trying to achieve here so that I will be able to help you in a better way.
Upvotes: 0
Reputation: 14738
I guess you are trying to achieve this:
String firstNametoPrint = firstname.getAttribute("value");
String lastNametoPrint = lastname.getAttribute("value");
System.out.println(firstNametoPrint+"\n"+lastNametoPrint);
Upvotes: 4
Reputation: 1571
System.out.println(String.format("Name %s, Surname %s",firstname, lastname));
Upvotes: 0
Reputation: 2799
Do the following:
System.out.println(firstname+"\n"+lastname);
Upvotes: 1