1- using BotSharp . Plugin . WebDriver . Services ;
2-
31namespace BotSharp . Plugin . WebDriver . Drivers . PlaywrightDriver ;
42
53public partial class PlaywrightWebDriver
64{
75 public async Task ClickElement ( Agent agent , BrowsingContextIn context , string messageId )
86 {
7+ var driverService = _services . GetRequiredService < WebDriverService > ( ) ;
8+
99 // Retrieve the page raw html and infer the element path
1010 var body = await _instance . Page . QuerySelectorAsync ( "body" ) ;
1111
@@ -23,18 +23,19 @@ public async Task ClickElement(Agent agent, BrowsingContextIn context, string me
2323 var text = await btn . TextContentAsync ( ) ;
2424 var name = await btn . GetAttributeAsync ( "name" ) ;
2525 var id = await btn . GetAttributeAsync ( "id" ) ;
26- str . Add ( $ "<button name='{ name } ' id='{ id } '>{ text } </button>") ;
26+ str . Add ( driverService . AssembleMarkup ( "button" , new MarkupProperties
27+ {
28+ Id = id ,
29+ Name = name ,
30+ Text = text
31+ } ) ) ;
2732 }
2833
29- var driverService = _services . GetRequiredService < WebDriverService > ( ) ;
30- var htmlElementContextOut = await driverService . LocateElement ( agent , string . Join ( "" , str ) , context . ElementName , messageId ) ;
31-
32- var tags = await _instance . Page . QuerySelectorAllAsync ( htmlElementContextOut . TagName ) ;
33- var button = tags [ htmlElementContextOut . Index ] ;
34- if ( button . AsElement ( ) == null )
35- {
36- throw new Exception ( $ "Can't find web element { context . ElementName } ") ;
37- }
38- await button . ClickAsync ( ) ;
34+ var htmlElementContextOut = await driverService . LocateElement ( agent ,
35+ string . Join ( "" , str ) ,
36+ context . ElementName ,
37+ messageId ) ;
38+ ILocator element = Locator ( htmlElementContextOut ) ;
39+ await element . ClickAsync ( ) ;
3940 }
4041}
0 commit comments