Select Element By Text in Selenium

后端 未结 4 886
眼角桃花
眼角桃花 2021-01-23 02:17

This may sound so simple but why there is no method to find element by its inner text without using xpath? for instance there is an element:

4条回答
  •  清歌不尽
    2021-01-23 03:07

    I think this works in java.

            WebElement chosenElement;
            List elements = driver.findElements(By.tagName("button"));
            for(WebElement element:elements){
                if(element.getText().equals("Some Text")){
                    chosenElement = element;
                    break;
                }
            }
    

提交回复
热议问题