Hi,
As per the recent upgrade, I've been trying to upgrade my project with the latest changes of selenium 3.11.
I'm facing issue with Lambda expressions for validating false conditions.
ISSUE DETAILS:
While running/debugging the below test using Lambda expressions
The system is not throwing an error for the true conditions with the lambda expressions.
for the false conditions, System is directly throwing no such element exception. it is not even going into the
IsElementDisplayed function to check the element is present or not.
If I use Old way of Initialising web elements like FindsBy then the system is going into isElementDisplayed function and returning false.
Can I get some resolution for this issue
Whenever I got a new build, I need to check the false conditions as there will be application errors on the page.
Test case:
Whenever I'm loading a web page I'll check whether all the fields are present(displayed) and no errors showed up as well.
Sample test Code:
Class1.cs
// OLD Way
[FindsBy(How = How.XPath, Using = "//*[@id='header']/h1[contains(text(),'Server Error')]")]
IWebElement error_Site_AppServerError _OLD { get; set; }
// New Way
IWebElement error_Site_AppServerError_New => DriverInstance.Driver.FindElement(By.XPath("//*[@id='header']/h1[contains(text(),'Server Error')]"));
IWebElement IMG_Logo_Tenant => DriverInstance.Driver.FindElement(By.XPath("//*[@id='tenant-logo']/img"));
[Test]
public void test1()
{
try
{
OpenBrowser("chrom");
NavigateToSite("https://mysite123.com");
Console.WriteLine("Helloooooo");
1 - Assert.That(IMG_Logo_Tenant.Displayed, Is.True);
2 - Assert.IsTrue(ElementHelper.IsElementDisplayed(IMG_Logo_Tenant));
3 - Assert.IsFalse(ElementHelper.IsElementDisplayed(error_Site_AppServerError _OLD)); [Returned False and execution proceeded to line 4]
4 - Assert.IsFalse(ElementHelper.IsElementDisplayed(error_Site_AppServerError_New)); [Directly throwed no such element without going into the iselementdisplayed function]
}
catch(Exception e)
{
cw(e.message);
}
}
public static bool IsElementDisplayed(IWebElement element)
{
try
{
bool ele = element.Displayed;
return true;
}
catch (Exception)
{
return false;
throw new Exception(string.Format("Element Not Displayed or Enabled Exception"));
}
}
Exception Info:
Result Message:
OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='header']/h1[contains(text(),'Server Error')]"}
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
please help in finding the resolution of above issue.
Thank you,
Phanee