I am using Selenium to find elements in an Instagram page.
I have successfully logged in and loaded a users profile, however am unable to load their following box.
When in a browser if you click the following link it loads up a box that you can scroll to see the following list.
When using selenium I have done the following -
var opt = new PhantomJSOptions();
opt.AddAdditionalCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36");
var driver = new PhantomJSDriver(driverService, opt);
var element = driver.FindElementByName("username");
element.SendKeys(userName);
element = driver.FindElementByName("password");
element.SendKeys(passWord);
// find the login button and click it after credentials have been populated
element = driver.FindElement(By.XPath("//button[.='Log in']"));
element.Click();
// Now navigate to the users page
driver.Navigate().GoToUrl("https://www.instagram.com/" + accName);
At this stage I am successfully logged in, on the users page and can find the following link and click it by doing -
var element = driver.FindElementByPartialLinkText("following");
element.Click();
However on the click event, this bizarrely takes me back to the main login page for Instagram.
Another thing I noticed is that if you are in the browser and click the link, the url in the browser updates to -
https://www.instagram.com/{username}/following/
However if you copy this link and paste it into a new window and try navigating to it it does not load the following box automatically as I expected, and just takes you to the users main page.
I have found examples in python where people seem to be successful using the click event e.g. example of using python.
How can I achieve this using the C#? I am not sure if Instagram have blocked this action completely.
I'm not sure if it is important but I am using a slightly older version of the Selenium Web Driver 3.8.0. It had also occurred to me to perhaps use a ChromeDriver
instead of PhantomJS
however not sure if this would make any difference.