You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Azure pipeline giving error An element could not be located at line var sessionb = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions); #2051
I am getting error:
ClassInitialize threw exception. OpenQA.Selenium.WebDriverException: OpenQA.Selenium.WebDriverException: An element could not be located on the page using the given search parameters..
2025-02-13T07:48:27.0449820Z Stack Trace:
2025-02-13T07:48:27.0450277Z at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
2025-02-13T07:48:27.0450578Z at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) 2025-02-13T07:48:27.0451173Z at OpenQA.Selenium.Appium.AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters) 2025-02-13T07:48:27.0452283Z at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) 2025-02-13T07:48:27.0452973Z at OpenQA.Selenium.Appium.AppiumDriver1.FindElementByName(String name)
on line:
var sessionb = new WindowsDriver(new Uri("http://127.0.0.1:4723"), appiumOptions);
in my local machine it's working fine but I am getting this error when I run it through azure pipeline.
It is a desktop application and I have used winappdriver to automate it.
Below tasks I have used for release pipeline but not sure whether it is opening the application or not
omkar4289 From your stack, looks like the Azure environment is slower than locally. Put a delay until the element with that name exists.
Check exists by a loop using FindElements instead of FindElement.
Jonathan Neal (@liljohnak)Shakevg
PFB:
public class SessionInit
{
protected static WindowsDriver sessionb;
protected static WindowsDriver session;
public static void StartSession(TestContext context)
{
string username = Environment.UserName;
var appiumOptions = new OpenQA.Selenium.Appium.AppiumOptions();
appiumOptions.AddAdditionalCapability("platformName", "Windows");
appiumOptions.AddAdditionalCapability("app", "Root");
appiumOptions.AddAdditionalCapability("deviceName", "WindowsPC");
Thread.Sleep(10000);
var sessionb = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions);
// Attaching to existing Application Window
var applicationwindow = sessionb.FindElementsByName("Hermes 5 (DEV) - HERMES_5_1_66_8.ECF 07/02/2025 19:07 (LIS_W1_66,PT_SHARE_66,ADMIN,ADMIN)");
foreach (WindowsElement element in applicationwindow)
{
if (element.Text.Contains("Hermes 5 (DEV)"))
{
var topLevelWindowHandle = element.GetAttribute("NativeWindowHandle");
topLevelWindowHandle = int.Parse(topLevelWindowHandle).ToString("X");
var appopt = new OpenQA.Selenium.Appium.AppiumOptions();
appopt.AddAdditionalCapability("appTopLevelWindow", topLevelWindowHandle);
session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appopt);
}
}
try { session.Manage().Window.Maximize(); } catch { }
}
public static void EndSession()
{
// Close the application and delete the session
if (session != null)
{
session.Close();
session.Quit();
session = null;
}
}
}
and I have test methods in below class
[TestClass]
public class OP_Exp_NOT_Out4 : SessionInit
{
[TestMethod]
public void Test()
{
string Scriptid;
Scriptid = "Exp_NTM_Out4";
//////create 1st Export flight
Thread.Sleep(1000);
session.FindElementByAccessibilityId("MDIClientForm").Click(); // to click in background
session.FindElementByAccessibilityId("2").FindElementByAccessibilityId("6").Click();
Fun_exp_createnewflight.execute(Scriptid); //Create new Exp flight
Thread.Sleep(2000);
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
StartSession(context);
}
}
I am getting error at line: session.FindElementByAccessibilityId("MDIClientForm").Click(); // to click in background
System.NullReferenceException: Object reference not set to an instance of an object.
may be because of session
omkar4289 for this one, all of the .FindElement() have an additional condition of being focusable and clickable. To relax these conditions use one of the .FindElements() methods and get the BoundingBox attribute. Then you can click the center of the bounding box.
Another possibility is you need a delay for the button to become visible.
Please check if winappdriver task has started successfully. Is it running with self hosted agent or Microsoft hosted agent? Also share the pipeline logs? I see that you are using powershell to run winappdriver.exe. Please introduce a sleep for 5 second.
Activity
liljohnak commentedon Feb 13, 2025
omkar4289 From your stack, looks like the Azure environment is slower than locally. Put a delay until the element with that name exists.
Check exists by a loop using FindElements instead of FindElement.
omkar4289 commentedon Feb 14, 2025
Hi Jonathan Neal (@liljohnak) ,
Thank you for your response.
Now I am getting below error:
System.NullReferenceException: Object reference not set to an instance of an object.
but same works fine when I run the code locally in my machine
Shakevg commentedon Feb 14, 2025
omkar4289 Please provide code example, try to use waiters
omkar4289 commentedon Feb 14, 2025
Jonathan Neal (@liljohnak) Shakevg
PFB:
public class SessionInit
{
protected static WindowsDriver sessionb;
protected static WindowsDriver session;
}
and I have test methods in below class
[TestClass]
public class OP_Exp_NOT_Out4 : SessionInit
{
[TestMethod]
public void Test()
{
string Scriptid;
Scriptid = "Exp_NTM_Out4";
//////create 1st Export flight
Thread.Sleep(1000);
session.FindElementByAccessibilityId("MDIClientForm").Click(); // to click in background
session.FindElementByAccessibilityId("2").FindElementByAccessibilityId("6").Click();
Fun_exp_createnewflight.execute(Scriptid); //Create new Exp flight
Thread.Sleep(2000);
}
}
I am getting error at line:
session.FindElementByAccessibilityId("MDIClientForm").Click(); // to click in background
System.NullReferenceException: Object reference not set to an instance of an object.
may be because of session
liljohnak commentedon Feb 14, 2025
omkar4289 for this one, all of the .FindElement() have an additional condition of being focusable and clickable. To relax these conditions use one of the .FindElements() methods and get the BoundingBox attribute. Then you can click the center of the bounding box.
Another possibility is you need a delay for the button to become visible.
omkar4289 commentedon Feb 17, 2025
Jonathan Neal (@liljohnak)
still its giving the same error.
System.NullReferenceException: Object reference not set to an instance of an object.
liljohnak commentedon Feb 17, 2025
Maybe a 500 error on WinAppDriver.exe?
anunay1 commentedon Mar 4, 2025
Please check if winappdriver task has started successfully. Is it running with self hosted agent or Microsoft hosted agent? Also share the pipeline logs? I see that you are using powershell to run winappdriver.exe. Please introduce a sleep for 5 second.