Is it possible to pass a IWebElement variable to an explicit wait condition instead of hard coding xpath values? Here is an example of what I'm trying to achieve. I would like to pass grant Email.GMSName variable as opposed to hard coding the xpath: /html/body/table/thead/tr/th[2]
try
{
WebDriverWait w = new WebDriverWait(Driver, TimeSpan.FromSeconds(20));
w.Until(ExpectedConditions.ElementExists(By.XPath(grantEmail.GMSName));
Assert.IsTrue(grantEmail.GrantNumber.Displayed);
Assert.IsTrue(grantEmail.GMSName.Displayed);
Assert.IsTrue(grantEmail.PIName.Displayed);
Assert.IsTrue(grantEmail.Institution.Displayed);
Assert.IsTrue(grantEmail.Title.Displayed);
Assert.IsTrue(grantEmail.PIReqAmt.Displayed);
Assert.IsTrue(grantEmail.DIVRecAmount.Displayed);
Assert.IsTrue(grantEmail.GMSRecAmount.Displayed);
Assert.IsTrue(grantEmail.GMORecAmount.Displayed);
Assert.IsTrue(grantEmail.DIVRank.Displayed);
Assert.IsTrue(grantEmail.RFAPA.Displayed);
Assert.IsTrue(grantEmail.PCC.Displayed);
Assert.IsTrue(grantEmail.PercentileScore.Displayed);
Assert.IsTrue(grantEmail.CouncilNPARS.Displayed);
Assert.IsTrue(grantEmail.NPARSProgramReqNumberofYears.Displayed);
Assert.IsTrue(grantEmail.CANPoolcode.Displayed);
Assert.IsTrue(grantEmail.BatchNumber.Displayed);
}
You can pass a
IWebElementobject as parameter toWebDriverWaitExpectedConditions.Similarly to syntax you presented in the question
where you passing a
grantEmail.GMSNameXPath expression.You can pass a
IWebElementobject, as following:where
Here you can see all the available
ExpectedConditions.As you can see, some of them accepting
Byas parameter and othersIWebElement.