1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Instagram Registering with Java

Discussion in 'General Programming Chat' started by HansSepp, Mar 15, 2017.

Tags:
  1. HansSepp

    HansSepp Newbie

    Joined:
    Mar 15, 2017
    Messages:
    10
    Likes Received:
    0
    Gender:
    Male
    Hey there, so the question is basically in the title, how would i go about this? Worked a bit with C# about that before, but didn't get it working there either, definitely preferring java, though.

    Thanks for any help. :)
     
  2. Crawlie

    Crawlie Registered Member

    Joined:
    Jan 2, 2017
    Messages:
    50
    Likes Received:
    8
    Gender:
    Male
    You need to add Selenium or HtmlUnit and use these headless browsers (or Chrome/Firefox drivers). Maybe later in the day I can write something more detailed if you want.
     
  3. HansSepp

    HansSepp Newbie

    Joined:
    Mar 15, 2017
    Messages:
    10
    Likes Received:
    0
    Gender:
    Male
    If you want, would be really helpful.
     
  4. Crawlie

    Crawlie Registered Member

    Joined:
    Jan 2, 2017
    Messages:
    50
    Likes Received:
    8
    Gender:
    Male
    Tested, works:

    Code:
    import org.openqa.selenium.By;
    import org.openqa.selenium.chrome.ChromeDriver;
    import java.util.concurrent.TimeUnit;
    
    public class Main {
        public static void main(String[] args) {
            System.setProperty("webdriver.chrome.driver","your path to chromdriver");
    
            ChromeDriver driver = new ChromeDriver();
            driver.get("https://www.instagram.com/?hl=en");
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.findElement(By.name("emailOrPhone")).sendKeys("veryimaginativeuser@gmail.com");
            driver.findElement(By.name("fullName")).sendKeys("Your Name");
            driver.findElement(By.name("username")).sendKeys("Your_username_xyz");
            driver.findElement(By.name("password")).sendKeys("yourpassword");
            driver.findElements(By.tagName("button")).get(1).click();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
    }
    
    You need to add Selenium jar to project and also download chromedriver.
     
    • Thanks Thanks x 1
  5. Crawlie

    Crawlie Registered Member

    Joined:
    Jan 2, 2017
    Messages:
    50
    Likes Received:
    8
    Gender:
    Male
    Oh and of course if you add wrong/invalid data to the input fields it won't log in...
     
  6. HansSepp

    HansSepp Newbie

    Joined:
    Mar 15, 2017
    Messages:
    10
    Likes Received:
    0
    Gender:
    Male
    Wow! Thank you so much man!