Output values from selenium webdriver to excel sheet -
Output values from selenium webdriver to excel sheet -
i using selenium webdriver output first 3 records using advanced search of linkedin in excel sheet not getting values of 'name' , 'description' fields except one. please this
public void testexport() throws exception { driver.get(baseurl + "/"); driver.findelement(by.id("session_key-login")).clear(); driver.findelement(by.id("session_key-login")).sendkeys("#####"); driver.findelement(by.id("session_password-login")).clear(); driver.findelement(by.id("session_password-login")).sendkeys("#####"); thread.sleep(1000); driver.findelement(by.xpath("//input[@value='sign in']")).click(); driver.manage().timeouts().implicitlywait(30, timeunit.seconds); driver.findelement(by.id("advanced-search")).click(); driver.findelement(by.id("adv-o-n-ffs")).click(); new select(driver.findelement(by.id("advscountrycode"))).selectbyvisibletext("united states"); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/legend")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/div/button")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/input")).sendkeys("leadmd"); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='pagekey-voltron_federated_search_internal_jsp']/div[1]/div/div[2]/ul/li[1]/img")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/div/button")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/input")).sendkeys("cloudwords"); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='pagekey-voltron_federated_search_internal_jsp']/div[1]/div/div[2]/ul/li[1]/img")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/div/button")).click(); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='adv-facet-cc']/fieldset/div/div/input")).sendkeys("grazitti"); thread.sleep(1000); driver.findelement(by.xpath(".//*[@id='pagekey-voltron_federated_search_internal_jsp']/div[1]/div/div[2]/ul/li[1]/img")).click(); thread.sleep(1000); driver.findelement(by.id("advs-title")).sendkeys("marketing"); driver.findelement(by.name("submit")).click(); thread.sleep(1000); string name, designation; for(int = 0; < 3; i++) { int j = + 1 ; name = driver.findelement(by.xpath(".//*[@id='results']/li["+j+"]/div/h3/a")).gettext(); system.out.println("data1 = " + name); designation = driver.findelement(by.xpath(".//*[@id='results']/li["+j+"]/div/p")).gettext(); system.out.println("data2 = " + designation); file fexcel = new file("c:\\users\\master\\desktop\\new.xls"); writableworkbook writablebook = workbook.createworkbook(fexcel); writablebook.createsheet("data", 0); writablesheet writablesheet = writablebook.getsheet(0); label data1 = new label(j, 1, name); writablesheet.addcell(data1); label data2 = new label(j, 1, designation); writablesheet.addcell(data2); writablebook.write(); writablebook.close(); } }
you creating new excel file overwriting previous 1 creating sheet within loop.
try modifying loop part of code below
file fexcel = new file("c:\\users\\master\\desktop\\new.xls"); writableworkbook writablebook = workbook.createworkbook(fexcel); writablebook.createsheet("data", 0); writablesheet writablesheet = writablebook.getsheet(0); for(int = 0; < 3; i++) { int j = + 1 ; name = driver.findelement(by.xpath(".//*[@id='results']/li["+j+"]/div/h3/a")).gettext(); system.out.println("data1 = " + name); designation = driver.findelement(by.xpath(".//*[@id='results']/li["+j+"]/div/p")).gettext(); system.out.println("data2 = " + designation); label data1 = new label(j, i, name); writablesheet.addcell(data1); label data2 = new label(j, i, designation); writablesheet.addcell(data2); } writablebook.write(); writablebook.close();
also new label (j,1,name)
means info getting added first row 1 after other. may alter new label (j,i,name)
each name-designation pair added new row.
let me know if helps you
selenium webdriver jxl
Comments
Post a Comment