Reputation: 898
I am trying to automate a sharepoint-based application, which can be slow at times. In the example below, I am trying to wrap the password input into an explicit wait. Currently, Selenium runs the test to fast and it results in failure to perform the actions.
How can I wrap the password portion into a selenium explicit way?
// Enter username
var input_Username = Driver.Instance.FindElement(By.Id("username_input"));
input_Username.SendKeys("admin");
WebDriverWait wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(3000));
// Enter pasword
var input_Password = Driver.Instance.FindElement(By.Id("pw_input"));
input_Password.SendKeys("password");
Upvotes: 0
Views: 178
Reputation: 32845
Yes, you are on the right track.
WebDriverWait
instance has been created, now you just need to call it like this:
WebDriverWait wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(3000));
var input_Password = wait.Until(d=> d.FindElement(By.Id("pw_input")));
input_Password.SendKeys("password");
Please refer to C# API doc for more details. Relevant classes are under OpenQA.Selenium.Support.UI
Namespace, in which there is an ExpectedConditions
class that would be handy.
var input_Password = wait.Until(ExpectedConditions.ElementExists(By.Id("pw_input")));
Also note that your code sets the timeout to 3000 seconds, seems way too long.
Upvotes: 2