1

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():
}
}
1

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.

1

I recommend not to use such classNames, they are dynamic in nature and changed frequently.

Find unique locator for userName field, i just gone through given instagram URL and found below Xpath. That works for you, try it .

//input[@aria-label='Phone number, username, or email']

Take a look on attached screenshot.enter image description here

Best!!!

1

From the screencapture attached by nishil81, would it not be simpler to use:

driver.findElement(By.xpath("//input[@name='username']").sendKeys("myUserName");

or even:

driver.findElement(By.name("username")).sendKeys("myUserName");

I would have thought that is more straightforward and simple.

Do check if either of the above work for you.

Good luck and welcome to the world of Se!

0

Looks like you selector className has multiple matches. So pass the index of the locator to use sendkeys. Else use the following command to get the unique identity of the locator.

driver.findElement(By.Id("f1c41bf87a84b3c")).sendKeys("myUserName");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.