0

I have written a simple code to enter email in facebook login page. But while entering the email value through sendKeys i am getting validation like "The method sendKeys(String) is undefined for the type By". I have already checked the compliance version which is 1.8. So what is going wrong here??. Below is code snippet:

package SeleniumTests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenFacebook {
    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver","geckodriver path");
        WebDriver driver=new FirefoxDriver();
        driver.get("http:\\facebook.com");
        driver.manage().window().maximize();
        driver.findElement(By.xpath("//[@id='email']").sendKeys("swarup.wipro@gmail.com");

    }

}

I am getting an option of Add cast to By.xpath as a quick fix. Can somebody explain the usage of this or is there any other solution available

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Swarup
  • 75
  • 2
  • 8

3 Answers3

1

As @KoustubhMadkaikar and @AndiCover mentioned, though adding the necessary closing bracket i.e. ) will solve the current issue but as per the best practices you should supply the tagName for your Locator Strategy to be robust and you can use either of the following solutions:

  • xpath:

    driver.findElement(By.xpath("//input[@id='email']")).sendKeys("swarup.wipro@gmail.com");
    
  • cssSelector:

    driver.findElement(By.cssSelector("input#email")).sendKeys("swarup.wipro@gmail.com");
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You missed closing round bracket ), use:

driver.findElement(By.xpath("//[@id='email']")).sendKeys("swarup.wipro@gmail.com");
Sers
  • 12,047
  • 2
  • 12
  • 31
0

A closing bracket is missing in your code before .sendKeys Try following:

driver.findElement(By.xpath("//[@id='email']")).sendKeys("swarup.wipro@gmail.com");
AndiCover
  • 1,724
  • 3
  • 17
  • 38