简体   繁体   中英

Extract data from multiple classes in selenium using java

The objective is to extract reviews from E-com website.How should i proceed to extract data from multiple classes using Selenium and then applying a for loop.Do i have to create an xpath with all the classes if yes how the syntax should be.There are few classes which contains data in string format and integers.

[Flipkart Reviews - class details]

class="_2xg6Ul" Brilliant

class="qwjRop" Best camera in smartphone period. Have note 8 and iPhone X also but pixel 2 with single lens beats them hands down

class= "_3LYOAd _3sxSiS" Flipkart Customer

class="_3LYOAd" 29 Nov, 2017

class="_1_BQL8" 142

Based on the very, very limited information you provided, this is what I came up with. You'll have to provide more information like the code you already have as well as the full HTML for each element.

  List<WebElement> list = driver.findElements(By.xpath("//body[contains(@class, '_')]"));

//Iterate through list
for(int i =0;i<list.size();i++) {
WebElement review = list.get(i);
System.out.println(review.getText());
}

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