Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.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# OpenQA.Selenium.ElementNotVisibleException';在WebDriver.dll中尝试单击链接时_C#_Visual Studio_Selenium Webdriver - Fatal编程技术网

C# OpenQA.Selenium.ElementNotVisibleException';在WebDriver.dll中尝试单击链接时

C# OpenQA.Selenium.ElementNotVisibleException';在WebDriver.dll中尝试单击链接时,c#,visual-studio,selenium-webdriver,C#,Visual Studio,Selenium Webdriver,我正在尝试用C#创建一个简单的自动化脚本,它将加载google主页,然后在搜索框中键入内容,列出结果,然后单击“图像”链接并显示搜索项目的可能图像 当Selenium Webdriver能够通过LinkText找到图像链接时,我已经能够做到这一点,但是当我想要执行Click()操作时,我在Webdriver.dll中抛出了错误消息Exception:“OpenQA.Selenium.ElementNotVisibleException”,我无法进一步移动 我把我的代码放在下面 using Sys

我正在尝试用C#创建一个简单的自动化脚本,它将加载google主页,然后在搜索框中键入内容,列出结果,然后单击“图像”链接并显示搜索项目的可能图像

当Selenium Webdriver能够通过LinkText找到图像链接时,我已经能够做到这一点,但是当我想要执行Click()操作时,我在Webdriver.dll中抛出了错误消息Exception:“OpenQA.Selenium.ElementNotVisibleException”,我无法进一步移动

我把我的代码放在下面

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace WebDriverDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.google.com";

           var searchBox = driver.FindElement(By.Id("lst-ib"));
           searchBox.SendKeys("apple");
           searchBox.SendKeys(Keys.Enter);

           driver.Manage().Timeouts().ImplicitWait = (TimeSpan.FromSeconds(10));


            try
            {
                var imageLink = driver.FindElement(By.LinkText("Images"));
                Console.Write("Element found by a LinkText");
                imageLink.Click();
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
            }
            Console.Read();

        }
    }
}
我期待您的反馈和可能的解决方案:)


向您致以最诚挚的问候和感谢,

我不知道为什么会这样:| 在尝试不同的“等待类型”后,似乎只有1个有效:

《睡眠》(2000年)


希望这对现在有所帮助。我仍在寻找更好的解决方法。

您只需在搜索后暂停片刻,等待图像链接可单击即可

Driver.FindElement(By.Id("lst-ib")).SendKeys("apple\n");
new WebDriverWait(Driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.LinkText("Images"))).Click();

另外,您可以发送
\n
,这是一个回车符,作为字符串的一部分。

很抱歉延迟了很长时间,但是我自己解决了这个问题。我没有使用driver.FindElement(By.LinkText(“Images”)),而是使用Xpath来显示图像链接的确切位置:)

谢谢你的支持