@@ -36,25 +36,23 @@ export async function clickPinContextButton(webview: WebviewView): Promise<void>
3636 * @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array
3737 */
3838export async function getPinContextMenuItems ( webview : WebviewView ) : Promise < { items : WebElement [ ] ; labels : string [ ] } > {
39- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
40- // TODO: Fix the need for a sleep function to be required at all.
41- await sleep ( 100 )
42- const menuListItems = await menuList . findElements ( By . css ( '.mynah-detailed-list-item.mynah-ui-clickable-item' ) )
39+ const items = await webview . findElements (
40+ By . xpath ( `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]` )
41+ )
4342
44- if ( menuListItems . length === 0 ) {
43+ if ( items . length === 0 ) {
4544 throw new Error ( 'No pin context menu items found' )
4645 }
4746
4847 const labels : string [ ] = [ ]
49- for ( const item of menuListItems ) {
50- const textWrapper = await item . findElement ( By . css ( '.mynah-detailed-list-item-text' ) )
51- const nameElement = await textWrapper . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
48+ for ( const item of items ) {
49+ const nameElement = await item . findElement ( By . css ( '.mynah-detailed-list-item-description' ) )
5250 const labelText = await nameElement . getText ( )
5351 labels . push ( labelText )
5452 console . log ( 'Menu item found:' , labelText )
5553 }
5654
57- return { items : menuListItems , labels }
55+ return { items, labels }
5856}
5957
6058/**
@@ -66,49 +64,38 @@ export async function getPinContextMenuItems(webview: WebviewView): Promise<{ it
6664 * NOTE: To find all possible text labels, you can call getPinContextMenuItems
6765 */
6866export async function clickPinContextMenuItem ( webview : WebviewView , itemName : string ) : Promise < void > {
69- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
70- await sleep ( 100 )
71- const menuListItems = await menuList . findElements ( By . css ( '.mynah-detailed-list-item.mynah-ui-clickable-item' ) )
72- for ( const item of menuListItems ) {
73- const textWrapper = await item . findElement ( By . css ( '.mynah-detailed-list-item-text' ) )
74- const nameElement = await textWrapper . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
75- const labelText = await nameElement . getText ( )
76-
77- if ( labelText === itemName ) {
78- console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
79- await item . click ( )
80- return
81- }
82- }
83-
84- throw new Error ( `Pin Context menu item not found: ${ itemName } ` )
67+ const item = await waitForElement (
68+ webview ,
69+ By . xpath (
70+ `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]//div[contains(@class, 'mynah-detailed-list-item-name') and text()='${ itemName } ']`
71+ )
72+ )
73+ console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
74+ await item . click ( )
8575}
8676/**
8777 * Lists all the possible Sub-menu items in the console.
8878 * @param webview The WebviewView instance
8979 * @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array
9080 */
9181export async function getSubMenuItems ( webview : WebviewView ) : Promise < { items : WebElement [ ] ; labels : string [ ] } > {
92- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
93- await sleep ( 100 )
94- const menuListItems = await menuList . findElements ( By . css ( '.mynah-detailed-list-item.mynah-ui-clickable-item' ) )
82+ const items = await webview . findElements (
83+ By . xpath ( `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]` )
84+ )
9585
96- if ( menuListItems . length === 0 ) {
86+ if ( items . length === 0 ) {
9787 throw new Error ( 'No sub-menu items found' )
9888 }
9989
10090 const labels : string [ ] = [ ]
101- for ( const item of menuListItems ) {
102- const textWrapper = await item . findElement (
103- By . css ( '.mynah-detailed-list-item-text.mynah-detailed-list-item-text-direction-row' )
104- )
105- const nameElement = await textWrapper . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
91+ for ( const item of items ) {
92+ const nameElement = await item . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
10693 const labelText = await nameElement . getText ( )
10794 labels . push ( labelText )
10895 console . log ( 'Menu item found:' , labelText )
10996 }
11097
111- return { items : menuListItems , labels }
98+ return { items, labels }
11299}
113100/**
114101 * Clicks a specific item in the Sub-Menu by its label text
@@ -119,22 +106,14 @@ export async function getSubMenuItems(webview: WebviewView): Promise<{ items: We
119106 * NOTE: To find all possible text labels, you can call getPinContextMenuItems
120107 */
121108export async function clickSubMenuItem ( webview : WebviewView , itemName : string ) : Promise < void > {
122- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
123- await sleep ( 100 )
124- const menuListItems = await menuList . findElements ( By . css ( '.mynah-detailed-list-item.mynah-ui-clickable-item' ) )
125- for ( const item of menuListItems ) {
126- const textWrapper = await item . findElement (
127- By . css ( '. mynah-detailed-list-item-text. mynah-detailed-list-item-text-direction-row' )
109+ // We require a sleep function of 0 so that the DOM of the SubMenu can load correctly.
110+ await sleep ( 0 )
111+ const item = await waitForElement (
112+ webview ,
113+ By . xpath (
114+ `//div[contains(@class, ' mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]//div[contains(@class, ' mynah-detailed-list-item-name') and text()=' ${ itemName } ']`
128115 )
129- const nameElement = await textWrapper . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
130- const labelText = await nameElement . getText ( )
131-
132- if ( labelText === itemName ) {
133- console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
134- await item . click ( )
135- return
136- }
137- }
138-
139- throw new Error ( `Pin Context menu item not found: ${ itemName } ` )
116+ )
117+ console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
118+ await item . click ( )
140119}
0 commit comments