invalid selector: The result of the xpath expression. It should be an element

问题: I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3 HTML code of the website: <div _ngcontent-c35="" cl...

问题:

I am writing automation test in selenium with javascript steps. In the test I want to check if TEXT3 equals TEXT3

HTML code of the website:

<div _ngcontent-c35="" class="content">
       <p>
          TEXT1
           <u>
             <strong>TEXT2</strong>
           </u> 
           TEXT3
         </p>
</div>

Javascript code:

this.Then(/^also "([^"]*)" as loanPurposeInfoDialogLabel03 is displayed$/, function (fieldValue, next) {
    var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text()[2]"));
     fieldText.getText().then(getFieldValue => {
      assert.equal(getFieldValue, fieldValue, next, 'Expected value of loanPurposeInfoDialogLabel03 (Text) to be: ' + fieldValue);
    }, next);
  });

Javascript code does not work in case I use /text() in XPATH

//div[@class='content']/p/text()[2]

I get error:

InvalidSelectorError: invalid selector: The result of the xpath expression "//div[@class='content']/p/text()[2]" is: [object Text]. It should be an element.

回答1:

Because you are giving text() function inside of xpath, please try following code :

var fieldText = this.driver.findElement(By.xpath("//div[@class='content']/p/text[2]"));
  • 发表于 2019-03-29 12:58
  • 阅读 ( 1276 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除