硒在页面上查找阵列内容



我正在使用Selenium使用Visual Studio来构建一个进入网页的应用程序,并发现该数组的内容是否在页面上。我遇到了搜索页面上的数组内容的问题。现在,它找不到,因此它在不应该的情况下单击下一页。

该数组来自我正在加载的CSV文件,它需要在页面上搜索CSV文件中任何记录的匹配并停止。

这是我到目前为止所拥有的:

        OpenFileDialog ofd = new OpenFileDialog();
    private double timeOut;
    private void bttnImportBrowse_Click(object sender, EventArgs e)
    {
        ofd.Filter = "CSV|*.csv";
        var fileInputs = new List<string>();
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            String chosenFile = ofd.FileName;
            String safeFileName = ofd.SafeFileName;
            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(chosenFile))
                {
                    string line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        //Console.WriteLine(line);
                        fileInputs.Add(line);
                        //Console.Write(string.Join(" ", fileInputs));
                        var driver = new ChromeDriver(@"C:Usersandre_000DocumentsVisual Studio 2015ProjectsMyProject");

                            driver.Navigate().GoToUrl("MySite");

                        var WebDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.XPath("/html/body/a[2]"))));
                        while (1==1) {
                            try
                            {
                                var result = driver.FindElement(By.LinkText(fileInputs.ToString())); 
                                break;
                            }
                            catch (NoSuchElementException n)
                            {
                                var nextBttn = driver.FindElementByXPath("/html/body/a[2]");
                                nextBttn.Click();
                            }
                        }
                    }
                }
            }
            catch (Exception entry)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(entry.Message);
            }
        }
    }

对不起,我会发表评论,但不允许。您有CSV文件吗?

我相信您正在尝试错误地找到链接文本。

当前在列表上调用ToString()

 var result = driver.FindElement(By.LinkText(fileInputs.ToString()));

可能应该是

 var result = driver.FindElement(By.LinkText(line));

最新更新