I can use click() function why but not sendKeys() in my code



  • I`m a novice on selenium testing, and I am trying to login to my instagram but I cant send keys to username but I can click on it.

    Code:

    WebDriver driver;
    public void invokeBrowser() 
    {
    
        try {
            System.setProperty("webdriver.chrome.driver","C:\\Users\\Uletic\\Desktop\\chromedriver.exe");
            driver = new ChromeDriver();
            driver.manage().deleteAllCookies();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
    
            driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher");
    
    
            LogIn();
        } 
        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    
    public void LogIn() 
    {
    
        driver.findElement(By.className("_9GP1n   ")).click();
        driver.findElement(By.className("_9GP1n   ")).sendKeys("myUserName");
    }
    
    public static void main(String[] args) 
    {
    
        Day1 myObj = new Day1();
        myObj.invokeBrowser():
    }
    }
    


  • Selenium does not support className locator with the value of having spaces.

    For example, in your code By.className("_9GP1n "), className contains spaces.
    Try using some other locators like XPath or CssSelector.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2