Home > Back-end >  WebdriverIO invalid selector: Unable to locate an element with the xpath expression
WebdriverIO invalid selector: Unable to locate an element with the xpath expression

Time:01-08

I am facing an issue selecting an element by going up the HTML dome with WebdriverIO. Note: It is easy to select the title by text and the h1 tag or by class name, but i don't want to do that.

Instead, i'd like the iframe tag to be my starting point and select it by partial src link text "nba-scores", then go back to the previous div with OR to the div with without selecting it by class name and once i am on the previous div go to the h1 tag and get the text with pageTitle.getText().

When i use:

get pageTitle(){return $("//iframe[contains(@src, 'nba-scores')]/parent::div//h1)")}

I am getting a SyntaxError: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//iframe[contains(@src, 'nba-scores')]/parent::div//h1)' is not a valid XPath expression.

Here is my HTML dome

<main>
  <div >
    <div >
       <h1 >NBA Scores</h1>
    </div>
    <iframe src="https://xyz/#/nba-scores/view" >
    </iframe>
  </div>
</main>

Any help would be appreciated!

CodePudding user response:

You indeed have a syntax error with a stray ) that is not opened and not necessary so change "//iframe[contains(@src, 'nba-scores')]/parent::div//h1)" to "//iframe[contains(@src, 'nba-scores')]/parent::div//h1"

  •  Tags:  
  • Related