add web driver get attribute value

This commit is contained in:
Jicheng Lu 2024-03-22 14:12:45 -05:00
parent 37716e3bde
commit b2ac5707ae
5 changed files with 36 additions and 2 deletions

View file

@ -24,4 +24,5 @@ public interface IWebBrowser
Task<T> EvaluateScript<T>(string conversationId, string script);
Task CloseBrowser(string conversationId);
Task<BrowserActionResult> SendHttpRequest(BrowserActionParams actionParams);
Task<string> GetAttributeValue(MessageInfo message, ElementLocatingArgs location, BrowserActionResult result);
}

View file

@ -26,4 +26,19 @@ public class VideoSnippet
public string Title { get; set; }
public string Description { get; set; }
public string ChannelTitle { get; set; }
public VideoThumbnails Thumbnails { get; set; }
}
public class VideoThumbnails
{
public ThumbnailData Default { get; set; }
public ThumbnailData Medium { get; set; }
public ThumbnailData High { get; set; }
}
public class ThumbnailData
{
public string Url { get; set; }
public decimal Width { get; set; }
public decimal Height { get; set; }
}

View file

@ -0,0 +1,18 @@
namespace BotSharp.Plugin.WebDriver.Drivers.PlaywrightDriver;
public partial class PlaywrightWebDriver
{
public async Task<string> GetAttributeValue(MessageInfo message, ElementLocatingArgs location, BrowserActionResult result)
{
var page = _instance.GetPage(message.ConversationId);
ILocator locator = page.Locator(result.Selector);
var value = string.Empty;
if (!string.IsNullOrEmpty(location?.AttributeName))
{
value = await locator.GetAttributeAsync(location.AttributeName);
}
return value ?? string.Empty;
}
}

View file

@ -45,7 +45,7 @@ public partial class PlaywrightWebDriver
}
}
if (location.Index > 0)
if (location.Index >= 0)
{
locator = locator.Nth(location.Index);
count = await locator.CountAsync();

View file

@ -224,7 +224,7 @@
"Youtube": {
"Endpoint": "https://www.googleapis.com/youtube/v3/search",
"RegionCode": "US",
"Part": "id"
"Part": "id,snippet"
}
},