I have an automated testing environment consisting of one development machine and two boxes that run the tests in an automated fashion. All three machines are running windows 10. All three are using the same verision of the WinAppDriver, and all three are using the latest version of Google Chrome. All three are running under logged in local admin accounts on the machines.
I initially built all my tests in IE, but due to browser instability have been trying to convert them over to Chrome.
In this particular instance, I am using the WinAppDriver to detect when the browser has presented the download dialogue to the user. It seems to be working correctly in IE on all the machines. It is even working correctly in Chrome on the development machine, but it will not work in Chrome on the testing machines.
So far I have been unable to figure out what could be different on the test machines, other than the fact that MSBuild is started by TFS on the test machines and by Visual Studio on the dev machine.
Here is an image of the results returned from the working dev machine.
Here are images of the results from one of the test machines.
As you can see, other than the flat out failure on the test machines, the only other difference appears to be in the response to the initial browser hook. The working one does not return a sessionId, while the failing one does. Which to me indicates a differences in product versions, but I verified the two versions of WinAppDriver were identical.
I have tried multiple versions of the XPath lookup, just in case that was the issue, but all of them work on the dev machine, and none of them have worked on the test machine.
Does anyone have any ideas why my test boxes are unable to perform this lookup specifically in Chrome?
Edit: Code was requested, it's a little redundant with the screenshots, but here it is.
this.BaseBrowser.NavigateToUrl(new System.Uri(string.Format("{0}&Export=Excel", MainDocument.PageUrl)));
var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(BaseBrowser.Window, new TimeSpan(0, 0, 0, 0, 5000)); // wait for 5 seconds
IWebElement export_cancel =
(Settings.TestBrowser == Brow.IE) ? wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath("//ToolBar/Button[@Name=\"Cancel\"]"))) :
(Settings.TestBrowser == Brow.Chrome) ? wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath("//Pane/Pane/Pane/Group/Button[@Name=\"Close\"]"))) :
null; // exception thrown on this if statement if browser is Chrome;
Mouse.Click(export_cancel);
And the text of the exception, also shown in the screenshots:
WebDriverException -> An element could not be located on the page using the given search parameters. StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary'2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath) at OpenQA.Selenium.By.<>c__DisplayClass19_0.b__0(ISearchContext context) at OpenQA.Selenium.By.FindElement(ISearchContext context) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) at SeleniumExtras.WaitHelpers.ExpectedConditions.<>c__DisplayClass6_0.b__0(IWebDriver driver) at OpenQA.Selenium.Support.UI.DefaultWait'1.Until[TResult](Func'2 condition)
EDIT 2: The BaseBrowser.Window method exerpt that hooks WinAppDriver into the browser process:
System.Diagnostics.Process[] localByName = System.Diagnostics.Process.GetProcessesByName(this.BaseProcessName);
foreach (System.Diagnostics.Process item in localByName)
{
if (item.MainWindowTitle == string.Format(BaseProcessTitleFormat, this.Title))
{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.SetCapability("appTopLevelWindow", item.MainWindowHandle.ToString("x"));
RemoteWebDriver session = new RemoteWebDriver(new Uri(windowsAppDriverUrl), desiredCapabilities, new TimeSpan(0, 1, 30));
_Window = session;
break;
}
}
return _Window;