normalize-space(.) versus text(.)

normalize-space(.) versus text(.)

if you want to locate a paragraph of text which contains some styling:

<p>A paragraph with <b>this text in bold</b>.</p>

?

This will not be matched by the following XPath:

//*[contains(text(), 'A paragraph with this text in bold')]

?

Whereas this XPath will match:

//*[contains(normalize-space(.), 'A paragraph with this text in bold')]

?

text(.) matches only against the text of the element, whereas normalize-space(.)

returns the text of the element, and of all the elements it contains.

要查看或添加评论,请登录

Reza Roozbehani的更多文章

  • Button

    Button

    Buttons can come in two forms - standard and submit buttons. Standard buttons are usually created by the ‘button’ tag…

  • Navigation - Visit pages within a site

    Navigation - Visit pages within a site

    Browsers provide various navigation methods to access web pages from the browser history or by refreshing the current…

  • Executing the JavaScript code

    Executing the JavaScript code

    The Selenium WebDriver API provides the ability to execute JavaScript code with the browser window. This is a very…

  • Performing double-click on an element

    Performing double-click on an element

    There will be elements in a web application that need double-click events fired to perform some actions. For example…

  • Checking an element's state

    Checking an element's state

    Many a time a test fails to click on an element or enter text in a field, as the element is disabled or exists in the…

  • Implicit Wait

    Implicit Wait

    In Java, if we want to wait for something, we can use the sleep method on the Thread class. This causes the program to…

  • Narrowing down by locating within chained search Contexts

    Narrowing down by locating within chained search Contexts

    You can combine search contexts together. For example, You have an element that is hard to find with a single locator.

  • Checking an element's presence

    Checking an element's presence

    The Selenium WebDriver does not implement Selenium RC's isElementPresent() method to check if an element is present on…

社区洞察

其他会员也浏览了