@@ -36,25 +36,24 @@ 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+ await sleep ( 1000 )
40+ const items = await webview . findElements (
41+ By . xpath ( `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]` )
42+ )
4343
44- if ( menuListItems . length === 0 ) {
44+ if ( items . length === 0 ) {
4545 throw new Error ( 'No pin context menu items found' )
4646 }
4747
4848 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' ) )
49+ for ( const item of items ) {
50+ const nameElement = await item . findElement ( By . css ( '.mynah-detailed-list-item-description' ) )
5251 const labelText = await nameElement . getText ( )
5352 labels . push ( labelText )
5453 console . log ( 'Menu item found:' , labelText )
5554 }
5655
57- return { items : menuListItems , labels }
56+ return { items, labels }
5857}
5958
6059/**
@@ -66,49 +65,40 @@ export async function getPinContextMenuItems(webview: WebviewView): Promise<{ it
6665 * NOTE: To find all possible text labels, you can call getPinContextMenuItems
6766 */
6867export async function clickPinContextMenuItem ( webview : WebviewView , itemName : string ) : Promise < void > {
69- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
7068 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 } ` )
69+ const item = await waitForElement (
70+ webview ,
71+ By . xpath (
72+ `//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 } ']`
73+ )
74+ )
75+ console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
76+ await item . click ( )
8577}
8678/**
8779 * Lists all the possible Sub-menu items in the console.
8880 * @param webview The WebviewView instance
8981 * @returns Promise<boolean> Returns the items as a WebElement List and the labels in a string array
9082 */
9183export async function getSubMenuItems ( webview : WebviewView ) : Promise < { items : WebElement [ ] ; labels : string [ ] } > {
92- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
9384 await sleep ( 100 )
94- const menuListItems = await menuList . findElements ( By . css ( '.mynah-detailed-list-item.mynah-ui-clickable-item' ) )
85+ const items = await webview . findElements (
86+ By . xpath ( `//div[contains(@class, 'mynah-detailed-list-item') and contains(@class, 'mynah-ui-clickable-item')]` )
87+ )
9588
96- if ( menuListItems . length === 0 ) {
89+ if ( items . length === 0 ) {
9790 throw new Error ( 'No sub-menu items found' )
9891 }
9992
10093 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' ) )
94+ for ( const item of items ) {
95+ const nameElement = await item . findElement ( By . css ( '.mynah-detailed-list-item-name' ) )
10696 const labelText = await nameElement . getText ( )
10797 labels . push ( labelText )
10898 console . log ( 'Menu item found:' , labelText )
10999 }
110100
111- return { items : menuListItems , labels }
101+ return { items, labels }
112102}
113103/**
114104 * Clicks a specific item in the Sub-Menu by its label text
@@ -119,22 +109,13 @@ export async function getSubMenuItems(webview: WebviewView): Promise<{ items: We
119109 * NOTE: To find all possible text labels, you can call getPinContextMenuItems
120110 */
121111export async function clickSubMenuItem ( webview : WebviewView , itemName : string ) : Promise < void > {
122- const menuList = await waitForElement ( webview , By . css ( '.mynah-detailed-list-items-block' ) )
123112 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' )
113+ const item = await waitForElement (
114+ webview ,
115+ By . xpath (
116+ `//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 } ']`
128117 )
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 } ` )
118+ )
119+ console . log ( `Clicking Pin Context menu item: ${ itemName } ` )
120+ await item . click ( )
140121}
0 commit comments