what is the difference between By.cssSelector and By.ByCssSelector in the below code.
driver.findElement(By.cssSelector("test")).click(); driver.findElement(By.ByCssSelector.id("")).click();
what is the difference between By.cssSelector and By.ByCssSelector in the below code.
driver.findElement(By.cssSelector("test")).click(); driver.findElement(By.ByCssSelector.id("")).click();
cssSelector
- static method of By Class.
ByCssSelector
- static inner class of By Class.
cssSelector
method internally creates ByCssSelector
class.
Hence
driver.findElement(By.cssSelector("test")).click();
can be written as
driver.findElement(new By.ByCssSelector("test")).click();
Both are same.
Update:
driver.findElement(By.ByCssSelector.id("test")).click();
Above statement is invalid since
findElement expects By
object and new
keyword is missing.
We have to pass css selector value when calling ByCssSelector
since it has
parameterized constructor which takes cssselector value.
ByCssSelector
inner class doesn't have id method to invoke.