Getting a visible button by name
The first enhancement in the getValidElement()
method is to allow a string to be passed, as with the three preceding methods:
export async function getValidElement( element: WebdriverIO.Element | String, elementType: string ): Promise<WebdriverIO.Element> {
The first check that we can perform is to see whether there are any elements that might match what we seek. In this case, we can leverage both an XPath and a CSS locator for a second time. This XPath locator will seek any node that contains the text passed to the method:
if (typeof element == "string") { // Try finding "Halloween Party" element by xPath text elements = await browser.$$(`//*[contains(normalize-space(),'${eleText}')]`)
If there are no elements returned, a second attempt will be done with a CSS selector using the href
property. This property often contains the text string...