Skip to content

Commit

Permalink
use locator
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit committed Jun 6, 2022
1 parent cf79848 commit ff20239
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,14 @@ import type { Editor } from './index';
export async function transformBlockTo( this: Editor, name: string ) {
await this.showBlockToolbar();

const switcherToggle = await this.page.waitForSelector(
const switcherToggle = this.page.locator(
'.block-editor-block-switcher__toggle'
);
await switcherToggle.evaluate( ( element ) => element.scrollIntoView() );
await this.page.waitForSelector( '.block-editor-block-switcher__toggle', {
state: 'visible',
} );
await switcherToggle.click();
await this.page.waitForSelector(
'.block-editor-block-switcher__container',
{
state: 'visible',
}
);

// Find the block button option within the switcher popover.
const xpath = `//*[contains(@class, "block-editor-block-switcher__popover")]//button[.='${ name }']`;
const insertButton = await this.page.waitForSelector( xpath, {
state: 'visible',
} );
const insertButton = this.page.locator( xpath );
// Clicks may fail if the button is out of view. Assure it is before click.
await insertButton.evaluate( ( element ) => element.scrollIntoView() );
await insertButton.click();
Expand Down

0 comments on commit ff20239

Please sign in to comment.