How to automate instagram login page using java in…
We can automate Instagram login page with Selenium webdriver in Java. To achieve this, first we have to launch the Instagram login page and identify the elements like email, password and login with the findElement method and interact with them.
Let us have the look at the Instagram login page −

Code Implementation
package RK1.Building_a_selenium_project;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
public class InstaLogin {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "F:\\Work Environment\\MyProject\\QA_Round\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//implicit wait
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//URL launch
driver.get("https://www.instagram.com/");
//identify username
WebElement l = driver
. findElement(By.name("username"));
l.sendKeys("test@gmail.com");
//identify password
WebElement p = driver
.findElement(By.name("password"));
p.sendKeys("test123");
WebElement b = driver
.findElement(By.className("Igw0E"));
b.click();
//obtain value entered for username
String s = l.getAttribute("value");
System.out.println("Value entered for username: " + s);
//quit browser
driver.quit();
}
}
Output:
Starting ChromeDriver 97.0.4692.71 (adefa7837d02a07a604c1e6eff0b3a09422ab88d-refs/branch-heads/4692@{#1247}) on port 13129
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Jan 19, 2022 11:39:02 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Value entered for username: test@gmail.com