Selenium getText

前端 未结 4 1719
庸人自扰
庸人自扰 2020-12-20 16:15

I want to getText() using By.id or By.cssSelector.

I managed to solve my problem by doing getAttribute("value"), but I don\'t understand why getText() doesn

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 17:04

    You may use this if you want to search for a given text on a WebElement. Pass it directly or through a string:

    String textoToSearch = "Text inside Webelement";
    driver.findElement(By.id("someID).getText().contains("textToSearch");
    

提交回复
热议问题