Reputation: 156
I have been trying to open different subreddits using selenium, but I can't seem to figure it out. I want to be able to open a specified number of subreddits, from a specified search term.
Usually, I would just put in the url, but I can't do that, because when the user inputs a different keyword, it would come up with different results. Here's the example link.
When I use inspect on the first 3 subreddits (the ones I want to click), I can't really see a real way to differentiate them, other than the subreddit name (can't use, as people will be using different search terms).
Any help would be much appreciated!
Using Visual Studio, C#, and selenium
Upvotes: 1
Views: 217
Reputation: 2326
Can locate all such links present in page using a common locator and then click all of them one by one:
IList<IWebElement> reditLinks= driver.FindElements(By.XPath("//span[text()='Communities and users']//following-sibling::div//a//div//div[contains(@class,'_2torGbn')]"));
// For current page, it will return list of 3 elements.
for (WebElement reditLink: reditLinks){
reditLinks.Click();
}
Note : I am no expert in C#, I am more of a Java / Python person. But idea here will work.
Upvotes: 1