[英]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. 我想问一下如何从没有unic id / class的元素中获取文本,我尝试使用xpath(从网络浏览器复制),但是这不起作用。
尝试下面的代码;
("//*[@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". 然后,您可以使用ArrayList来获取要使用的文本,也可以使用“内容”。 If this does not work, you can get the inner HTML and work with it to get the right context you want. 如果这不起作用,则可以获取内部HTML并对其进行处理以获得所需的正确上下文。 You can get innerHTML as follows: 您可以按以下方式获取innerHTML:
String inHTML = driver.findElement(By.className("text-grey")).getAttribute("innerHTML");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.