Skip to content

Commit

Permalink
Merge pull request #62 from FlaUI/find-desktop-elements
Browse files Browse the repository at this point in the history
Add ability to find desktop elements
  • Loading branch information
aristotelos authored Aug 26, 2024
2 parents b84a2ec + 666feb6 commit d463d38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/FlaUI.WebDriver.UITests/FindElementsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ namespace FlaUI.WebDriver.UITests
{
public class FindElementsTests
{
[Test]
public void FindElement_FromRoot_ReturnsElement()
{
var driverOptions = FlaUIDriverOptions.RootApp();
using var driver = new RemoteWebDriver(WebDriverFixture.WebDriverUrl, driverOptions);

var element = driver.FindElement(By.Name("Taskbar"));

Assert.That(element, Is.Not.Null);
}

[Test]
public void FindElement_ByXPath_ReturnsElement()
{
Expand Down
6 changes: 3 additions & 3 deletions src/FlaUI.WebDriver/Controllers/FindElementsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public FindElementsController(ILogger<FindElementsController> logger, ISessionRe
public async Task<ActionResult> FindElement([FromRoute] string sessionId, [FromBody] FindElementRequest findElementRequest)
{
var session = GetActiveSession(sessionId);
return await FindElementFrom(() => session.CurrentWindow, findElementRequest, session);
return await FindElementFrom(() => session.App == null ? session.Automation.GetDesktop() : session.CurrentWindow, findElementRequest, session);
}

[HttpPost("element/{elementId}/element")]
Expand All @@ -39,7 +39,7 @@ public async Task<ActionResult> FindElementFromElement([FromRoute] string sessio
public async Task<ActionResult> FindElements([FromRoute] string sessionId, [FromBody] FindElementRequest findElementRequest)
{
var session = GetActiveSession(sessionId);
return await FindElementsFrom(() => session.CurrentWindow, findElementRequest, session);
return await FindElementsFrom(() => session.App == null ? session.Automation.GetDesktop() : session.CurrentWindow, findElementRequest, session);
}

[HttpPost("element/{elementId}/elements")]
Expand Down Expand Up @@ -203,7 +203,7 @@ private AutomationElement GetElement(Session session, string elementId)
private Session GetActiveSession(string sessionId)
{
var session = GetSession(sessionId);
if (session.App == null || session.App.HasExited)
if (session.App != null && session.App.HasExited)
{
throw WebDriverResponseException.NoWindowsOpenForSession();
}
Expand Down

0 comments on commit d463d38

Please sign in to comment.