Reputation: 1832
I'm trying to make a simple C# program which will give me a list of followers of my public profile. I managed to get the driver connect to the provided URL and now I'm trying to click on the Followers button but get the exception:
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":".\-nal3"}
I read in another SO post about having to wait for the page to load before trying to click the element but the solution doesn't work for me (org.openqa.selenium.ElementClickInterceptedException: element click intercepted error using Selenium and Java in headless mode).
My code so far:
public void Run(string profileName)
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--headless");
options.AddArgument("--no-sandbox");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("start-maximized");
options.AddArgument("--remote-debugging-port=9222");
IWebDriver driver = new ChromeDriver(options);
string url = "http://www.instagram.com/" + profileName + "/";
driver.Navigate().GoToUrl(url);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement followersButton = wait.Until(driver => driver.FindElement(By.ClassName("-nal3")));
followersButton.Click();
}
I've also tried finding the element by the XPath with the same result.
What am I doing wrong?
UPDATE:
I've created a separate string variable in my code to easily debug and see the source of the page which is returned and then opened Visual Studio's HTML Visualizer and it shows a page which says some active elements were restricted. How can I enable them in my code?
Upvotes: 0
Views: 203
Reputation: 3801
The problem is there are 3 of those -nal3
Class Names on that page, one for posts
, followers
, and following
Try this XPath instead, to narrow it down to just the followers
link:
//ul[@class='k9GMp ']/li[2]/a
Upvotes: 0