UPDATED VERSION
I'm trying to find a more dynamic way to wait for elements instead of using static wait functions like Task.Event(2000).Wait();
The solution to this seems to be this:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[2]/div/input")));
But when I use this function, the "ExpectedConditions" always lights up red indicating that it: "does not exist in the current context".
I've placed the function in one of my testcases:
(I am using C#/Visual Studios, Project type: Classlibrary)
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public class MyFirstTest
{
IWebDriver driver = new FirefoxDriver();
[Test]
public void WaitverifyTest()
{
driver.Navigate().GoToUrl("https://www.google.se/");
driver.Manage().Window.Maximize();
Task.Delay(4000).Wait();
driver.FindElement(By.XPath("//div[2]/div/input")).SendKeys("Selenium");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[2]/div/input")));
element.Click();
driver.FindElement(By.XPath("//center/input")).Click();
}
}
}
(The xpath is a location type xpath, it is valid and works in both Selenium IDE and in Visual Studios.)
Anyone has any idea what I'm doing wrong?
I have two suspicions:
According to selenium.io , ExpectedCondition was last updated in 3.1.0. Maybe it is no longer vaild. Is there someway to check this?
I've seen this before.
Make sure you've installed both the Selenium.Webdriver and Selenium.Support NuGet packages for your project. You'll need the Selenium.Support package to use ExpectedConditions.