简体   繁体   中英

How to open multiple links in different windows using selenium and C#

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM