Need help extacting webpage data to excel using Selenium IDE

30 views
Skip to first unread message

rodrr...@gmail.com

unread,
Jul 28, 2015, 8:24:20 AM7/28/15
to Selenium Users
Hi. New Seleninum IDE user here.
I've learned the basics on how to automate navigating to a webpage using Seleninum IDE... but now I'd like to have Seleninum automatically dump the contents (text) of this webpage to an excel file.
Can someone point me in the right direction on how to do this?
thanks!

Mercious

unread,
Jul 28, 2015, 9:56:16 AM7/28/15
to Selenium Users, rodrr...@gmail.com
You should rather use a scapping-framework (Like Jsoup in Java) for this purpose.

But in Selenium you can also acquire the documents body. 

For example, using By.tagName("body")

Sonia saini

unread,
Jul 28, 2015, 10:25:37 AM7/28/15
to seleniu...@googlegroups.com, rodrr...@gmail.com
It is more related to your logic. Have done something like below. you can alter in your way.


WebElement Electronics=driver.findElement(By.xpath("//li[@data-key='electronics']"));

 Actions act=new Actions(driver);

 act.moveToElement(Electronics).build().perform();

 WebElement SamsungBrands=driver.findElement(By.xpath("//a[@data-tracking-id='0_Samsung']"));

 Thread.sleep(5000);

 act.moveToElement(SamsungBrands).click().build().perform();

 Thread.sleep(5000);

 JavascriptExecutor js=((JavascriptExecutor)driver);

 WebElement scroll=driver.findElement(By.xpath("//div[@id='show-more-results']"));

 while(!scroll.isDisplayed())

{   js.executeScript("window.scrollBy(0,800)", "");

Thread.sleep(5000);  }  

        //js.executeScript("window.scrollBy(20000,0)", "");

 

 File fExcel=new File("\\C:\\Mobile.xls");

 WritableWorkbook wbook=jxl.Workbook.createWorkbook(fExcel);

 wbook.createSheet("Samsung_Models", 0);

 WritableSheet Writable=wbook.getSheet(0);

 Label C1Name=new Label(0,0, "MOBILE MODELS");

 Writable.addCell(C1Name);


 Label C2Name=new Label(2,0, "OFFER PRICE");

 Writable.addCell(C2Name);

 int i=1;

 List<WebElement> AllModelNames=driver.findElements(By.xpath("//div[@class='pu-title fk-font-13']"));



 List<WebElement> Price=driver.findElements(By.xpath("//div[@class='pu-final']"));

    int TotalItems=AllModelNames.size();  

 

 Iterator<WebElement> itr = AllModelNames.iterator();

 Iterator<WebElement> itr1 = Price.iterator();


 while(itr.hasNext() || itr1.hasNext() )

   { String Model=itr.next().getText();

      Label data1=new Label(0,i,Model);

      Writable.addCell(data1); 

     String Pric=itr1.next().getText();

      Label data2=new Label(1,i,Pric);

 Writable.addCell(data2); 

    

 i=i+1; }

 driver.close(); 

 wbook.write();

 wbook.close();

 }

}



List<String> result = new ArrayList<String>();

for (String next : file) {

   if (next != null && next.length() != 0) result.add(next);

}


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/fe95de11-2fa1-41db-a79b-afcff47fd980%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Sonia saini
Reply all
Reply to author
Forward
0 new messages