Find element with selenium by display text

后端 未结 2 1213
温柔的废话
温柔的废话 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:42

    You are using incorrect syntax of xpath in By.Xpath and By.LinkText works only on a element with text and By.ClassName looks ok but may be there are more elements with that class name that's why you couldn't get right element, So you should try use below provided xPath with text :-

    driver.FindElement(By.XPath("//div[text() = 'TextToFind']"));
    

    Or

    driver.FindElement(By.XPath("//div[. = 'TextToFind']"));
    

    Or

    driver.FindElement(By.XPath("//*[contains(., 'TextToFind')]"));
    

    Hope it works...:)

提交回复
热议问题