Can we pass more than one parameter in sendKeys() method



==========Selenium sendKeys Method ==============

public class Links {

public static void main(String[] args) throws Exception {

System.setProperty("webdriver.chrome.driver", "E:\\Selenium\\selenium-java-3.5.0\\Browser Exe\\Chromedriver.exe");
WebDriver driver = new ChromeDriver();
//driver.manage().window().maximize();
driver.get("https://www.linkedin.com/");
driver.findElement(By.id("reg-firstname")).sendKeys("Test ", "Best ", "Rest ");
driver.close();
}
}

===================seendKeys() Method with parameter =========================



====================Explanation ================

 CharSequence represents an interface to a sequence of characters, with operations common to all classes implementing it. Mutability is not enforced by this interface, So, you can have an immutable implementing class, like String or mutable ones, like StringBuilder and StringBuffer.

Since CharSequence  is the parent interface for all these class thus we can cast all the sub classes into this type. so this is the reason behind accepting the Sting, so when we pass the string it will e automatically upcasted in to CharSequence.

and  ... (three dots) in Java known as "ellipsis", now varrags allows the method to accept zero or muliple arguments. Before varargs either we use overloaded method or take an array as the method parameter but it was not considered good because it leads to the maintenance problem. If we don't know how many argument we will have to pass in the method, varargs is the better approach.

Always remember "Varargs" stands for Variable Argument .

The varargs uses ellipsis i.e. three dots after the data type. Syntax is as follows:

return_type method_name(data_type... variableName){}

  1. Aman said...

    https://youtu.be/eYcYSvfyi2E

Post a Comment