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():
}
}
Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked Sep 21, 2018 at 23:57

4 Answers 4

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.

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered Sep 24, 2018 at 5:59
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!!!

answered Sep 24, 2018 at 6:38
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!

answered Sep 25, 2018 at 7:05
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");
answered Sep 22, 2018 at 12:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.