Renuka
Renuka

Reputation: 1

System.InvalidOperationException occurred in webdriver.dll

Below is my code :

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using NUnit.Framework;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;

namespace Test01
{
    class Program
    {
        static void Main(string[] args)
        {

            IWebDriver webDriver = new EdgeDriver(@"C:\Users\renuka.rani\Desktop\Selenium projects\Test01");
            webDriver.Navigate().GoToUrl("http://d2ubgnp33uouus.cloudfront.net/");
            webDriver.Manage().Window.Maximize();
            webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            webDriver.FindElement(By.XPath(".//*[@id='main']/header/div/div/div/div[1]/ul/li[1]/a")).Click();

            webDriver.FindElement(By.Name("email")).SendKeys("[email protected]");
            webDriver.FindElement(By.Name("password")).SendKeys("renukarani");
            webDriver.FindElement(By.Name("btnSignInTest")).Click();
            webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            string actualText = webDriver.FindElement(By.LinkText("Renuka")).GetAttribute("Renuka");
            Assert.AreEqual(actualText, "Renuka");
            Actions builder = new Actions(webDriver);
            builder.MoveToElement(webDriver.FindElement(By.LinkText("MyTradingpost"))).Click().Build().Perform();

            webDriver.Quit();

        }
    }
}`

when it reaches this line

webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
webDriver.FindElement(By.XPath(".//*[@id='main']/header/div/div/div/div[1]/ul/li[1]/a")).Click();

it throws exception

System.InvalidOperationException occurred in webdriver.dll ". Its not able to click hyperlink "Sign in".

Upvotes: 0

Views: 1332

Answers (1)

Boopeshwar
Boopeshwar

Reputation: 19

Sometimes there will be delay during the initiation of the webelement and it shall be handled through inducing delay. The mocked code of yours worked with me.

    static void Main(string[] args)
    {

        IWebDriver driver;
        driver = new ChromeDriver();
        driver.Navigate().GoToUrl("http://d2ubgnp33uouus.cloudfront.net/");
        driver.Manage().Window.Maximize();
        Thread.Sleep(2000);
        //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
        driver.FindElement(By.XPath(".//*[@id='main']/header/div/div/div/div[1]/ul/li[1]/a")).Click();
        Thread.Sleep(3000);
        driver.FindElement(By.Name("email")).SendKeys("[email protected]");
        driver.FindElement(By.Name("password")).SendKeys("renukarani");
        driver.FindElement(By.Name("btnSignInTest")).Click();
        Thread.Sleep(3000);
        //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
        // string actualText = driver.FindElement(By.LinkText("Renuka")).GetAttribute("Renuka");
        IWebElement user = driver.FindElement(By.XPath("//*[@id='main']/header/div/div/div/div[1]/ul/li[1]/a/strong"));

        String actualText = user.Text;
        if (actualText.Equals("Renuka"))
        {
            Actions builder = new Actions(driver);
            Thread.Sleep(2000);
            builder.MoveToElement(driver.FindElement(By.XPath("//*[@id='main']/header/div/div/div/div[1]/ul/li[2]/ul/li[7]/a"))).Click().Build().Perform();
            driver.Quit();

        }
    }
}

}

Upvotes: 1

Related Questions