C#硒键
我试图一次提交一个字符串列表,而不是通过一个文本文件,使用findelement提供的selenium中的sendkeys 用法示例:C#硒键,c#,selenium,C#,Selenium,我试图一次提交一个字符串列表,而不是通过一个文本文件,使用findelement提供的selenium中的sendkeys 用法示例: driver.FindElement(By.Name("search")).SendKeys(line); 我现在使用的是一个foreach循环来遍历列表,并分别使用当前行/字符串发送请求: foreach (String line in File.ReadAllLines(@"input.txt")) {
driver.FindElement(By.Name("search")).SendKeys(line);
我现在使用的是一个foreach循环来遍历列表,并分别使用当前行/字符串发送请求:
foreach (String line in File.ReadAllLines(@"input.txt"))
{
string search = line;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.Name("search")));
if (driver.FindElements(By.Name("search")).Count != 0)
{
driver.FindElement(By.Name("search")).SendKeys(search);
}
driver.FindElement(By.Name("srchbtn")).Click();
Results();
}
然而,该网站允许每次搜索最多100个字符串,因此,与其每次请求发送1个字符串,我宁愿排队发送100。。如何从文本文件中提取前100个字符串,并将它们作为列表输入sendkeys,然后输入下100行,依此类推
我确实试过:
var Lines = File.ReadLines(@"input.txt").Take(100).ToList();
driver.FindElement(By.Name("search")).SendKeys(Lines);
但它返回了一个错误,指出:
cannot convert from 'System.Collections.Generic.List<string>' to 'string'
无法从“System.Collections.Generic.List”转换为“string”
发送前加入字符串
var query = string.Join(" ", Lines);
driver.FindElement(By.Name("search")).SendKeys(query);
在发送前加入字符串
var query = string.Join(" ", Lines);
driver.FindElement(By.Name("search")).SendKeys(query);
我需要每个字符串位于新行:/replace“”与Environment.NewLine我需要每个字符串位于新行:/replace“”与Environment.NewLine