How to automate instagram login page using java in selenium

+1 vote

Using below code i am able to open Instagram but i am not able enter user name password and further process please help

package logintesting;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class Loginpage  {

public static void main(String[] args)  {

System.setProperty("webdriver.chrome.driver","D:\\selenium\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

//driver.get("https://www.google.com/");

driver.get("https://www.instagram.com/");

driver.manage().window().maximize();

WebElement e = driver.findElement(By.name("q"));

e.sendKeys("Instagram");

e.submit();

//WebElement click = driver.findElement(By.xpath("//div[@class='g']//div//div[@class='rc']//h3[@class='LC20lb DKV0Md'][contains(text(),'Instagram')]]"));

//click.click();

driver.findElement(By.name("UserName")).sendKeys("xyz");

driver.findElement(By.name("password")).sendKeys("abci");

driver.findElement(By.xpath("//div[text()='Log In']")).click();
Sep 15, 2020 in Selenium by anonymous
• 410 points
6,528 views

1 answer to this question.

+1 vote
Best answer

Try the following:

package com.company;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.By;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","chromedriver");

        ChromeDriver driver = new ChromeDriver();
        driver.get("https://www.instagram.com/accounts/login/?hl=en&source=auth_switcher");

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        driver.findElement(By.name("username")).sendKeys("username");
        driver.findElement(By.name("password")).sendKeys("password");
        driver.findElement(By.xpath("//div[text()='Log In']")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
}
answered Sep 15, 2020 by Karan
• 19,610 points

selected Sep 17, 2020 by Jordan

Related Questions In Selenium

+10 votes
17 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,360 points
194,267 views
0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
18,512 views
+1 vote
2 answers
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,978 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,764 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,628 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,703 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,565 views
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13, 2020 in Selenium by Karan
• 19,610 points
7,873 views
0 votes
2 answers

How to read OTP in JAVA Selenium using android phone

Try the following: Step 1: Connect the Phone/Dongle ...READ MORE

answered Oct 7, 2020 in Selenium by Karan
• 19,610 points
4,690 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP