简体   繁体   English

如何从Selenium Java中没有Unic ID或类的Web元素获取文本

[英]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.

相关问题 硒:无法从类元素中获取文本 - Selenium: Can't get text from a class element Selenium Web Driver Java Element 类如何? - Selenium Web Driver Java Element class How? 如何通过Selenium和Java在同一标签中定位多个元素具有相同id、名称和属性的元素 - How to locate an element where multiple elements have same id, name and attributes in same tags through Selenium and Java 如何使用Selenium Webdriver和Java从元素中获取文本? - How can I get text from element with Selenium webdriver and Java? Selenium java如何从第二个引号“”中的元素获取文本 - Selenium java how to get text from element in second quotes "" 从Web表格中的元素获取文本,而无需使用XPath(Selenium Web驱动程序+ Java) - Get Text from element inside a webtable without using XPath(Selenium Web driver + Java) Selenium WebDriver-当元素具有动态ID时如何获取元素的ID? - Selenium WebDriver - How to get id of the element when they have dynamic id? 如何从没有ID或Class的标签中获取文本 - How to get a text from a tag that do not have ID or Class 在Selenium Web驱动程序Java中获取元素的类名称 - Get class name of the element in selenium web driver java 如何从jSoup Java中没有id和class的div中获取文本 - How to get text from div that has no id and class in jSoup Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM