简体   繁体   中英

How to get text from web element where didn't have unic id or class in selenium java

I want to ask how to get the text from element where didnt have unic id/class, i tried using xpath(copied from web browser) but it's not working this is the picture.

这是图片

尝试下面的代码;

("//*[@class='col-sm-4']//*[@class='text-grey'][1]").getText();

This might help.

Document doc = Jsoup.parse(driver.getPageSource());
Elements content = doc.select("span[class^=text-grey]");
ArrayList<String> allTextIntextGreyClass = (ArrayList<String>) content.eachText();

Then you can work with ArrayList to get the text you want to work with, or you can work with "content". If this does not work, you can get the inner HTML and work with it to get the right context you want. You can get innerHTML as follows:

String inHTML = driver.findElement(By.className("text-grey")).getAttribute("innerHTML");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM