Skip to content

Commit 59191c8

Browse files
committed
partial fix for retry
1 parent 7a8c789 commit 59191c8

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

src/Bellatrix.Playwright/llm/FindByPrompt.cs

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,22 @@ private FindStrategy TryResolveLocator(string location, IViewSnapshotProvider sn
5959
if (_tryResolveFromPages)
6060
{
6161
var ragLocator = TryResolveFromPageObjectMemory(Value);
62-
if (ragLocator != null)
62+
if (ragLocator != null && ragLocator.Resolve(WrappedBrowser.CurrentPage).All().Any())
6363
{
64-
try
65-
{
66-
ragLocator.Resolve(WrappedBrowser.CurrentPage).IsVisible();
67-
Logger.LogInformation($"✅ Using RAG-located element '{ragLocator}' For '${Value}'");
68-
return ragLocator;
69-
}
70-
catch
71-
{
72-
// continue
73-
}
64+
Logger.LogInformation($"✅ Using RAG-located element '{ragLocator}' For '${Value}'");
65+
return ragLocator;
7466
}
7567
}
7668

7769
// Step 2: Try local persistent cache
7870
Logger.LogInformation("⚠️ RAG-located element not present. Trying cached selectors...");
7971
var cached = LocatorCacheService.TryGetCached(WrappedBrowser.CurrentPage.Url, Value);
80-
if (!string.IsNullOrEmpty(cached))
81-
{
82-
try
83-
{
84-
var strategy = new FindXpathStrategy(cached);
85-
strategy.Resolve(WrappedBrowser.CurrentPage).IsVisible();
8672

87-
Logger.LogInformation("✅ Using cached selector.");
88-
return strategy;
89-
}
90-
catch
91-
{
92-
// continue
93-
}
73+
var strategy = new FindXpathStrategy(cached);
74+
if (!string.IsNullOrEmpty(cached) && strategy.Resolve(WrappedBrowser.CurrentPage).All().Any())
75+
{
76+
Logger.LogInformation("✅ Using cached selector.");
77+
return strategy;
9478
}
9579

9680
// Step 3: Fall back to AI + prompt regeneration
@@ -160,19 +144,11 @@ private FindStrategy ResolveViaPromptFallback(string location, IViewSnapshotProv
160144
var result = SemanticKernelService.Kernel.InvokePromptAsync(prompt).Result;
161145
var rawSelector = result?.GetValue<string>()?.Trim();
162146

163-
if (!string.IsNullOrWhiteSpace(rawSelector))
147+
var strategy = new FindXpathStrategy(rawSelector);
148+
if (!string.IsNullOrWhiteSpace(rawSelector) && strategy.Resolve(WrappedBrowser.CurrentPage).All().Any())
164149
{
165-
var strategy = new FindXpathStrategy(rawSelector);
166-
try
167-
{
168-
_ = strategy.Resolve(WrappedBrowser.CurrentPage).IsVisible();
169-
LocatorCacheService.Update(location, Value, strategy.Value);
170-
return strategy;
171-
}
172-
catch
173-
{
174-
// continue
175-
}
150+
LocatorCacheService.Update(location, Value, strategy.Value);
151+
return strategy;
176152
}
177153

178154
failedSelectors.Add(rawSelector);

0 commit comments

Comments
 (0)