Find element with selenium by display text

后端 未结 2 1272
温柔的废话
温柔的废话 2021-02-20 02:40

I am trying to hover over an element in a menu bar with selenium, but having difficulty locating the element. The element is displayed below :

2条回答
  •  情话喂你
    2021-02-20 03:43

    Better ignoring the whitespaces around the text with this:

    var elm = driver.FindElement(By.XPath("//a[normalize-space() = 'TextToFind']"));
    

    This searches text within an [a] element, you can replace it with any element you are interested in (div, span etc.).

提交回复
热议问题