Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用selenium和C在不同的窗口中打开多个链接#_C#_Selenium_Selenium Webdriver - Fatal编程技术网

C# 如何使用selenium和C在不同的窗口中打开多个链接#

C# 如何使用selenium和C在不同的窗口中打开多个链接#,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,我一直在尝试使用selenium打开不同的子Reddit,但我似乎无法理解。我希望能够从指定的搜索词中打开指定数量的子Reddit 通常,我只会输入url,但我不能这样做,因为当用户输入不同的关键字时,会得到不同的结果。这是我的建议 当我在前3个子网站(我想点击的网站)上使用inspect时,除了子网站名称(不能使用,因为人们会使用不同的搜索词),我真的看不到区分它们的真正方法 任何帮助都将不胜感激 使用Visual Studio、C#和selenium可以使用通用定位器定位页面中的所有此类链接

我一直在尝试使用selenium打开不同的子Reddit,但我似乎无法理解。我希望能够从指定的搜索词中打开指定数量的子Reddit

通常,我只会输入url,但我不能这样做,因为当用户输入不同的关键字时,会得到不同的结果。这是我的建议

当我在前3个子网站(我想点击的网站)上使用inspect时,除了子网站名称(不能使用,因为人们会使用不同的搜索词),我真的看不到区分它们的真正方法

任何帮助都将不胜感激


使用Visual Studio、C#和selenium

可以使用通用定位器定位页面中的所有此类链接,然后逐个单击它们:

 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();
    }
IList-reditLinks=driver.FindElements(By.XPath(//span[text()='Communities and users']//以下同级::div//a//div//div[contains(@class,''u 2torGbn')]);
//对于当前页面,它将返回3个元素的列表。
对于(WebElement reditLink:reditLink){
reditLinks.Click();
}
注意:我不是C#方面的专家,我更喜欢Java/Python。但这个想法会奏效