Home > Net >  I am getting error -**The method getAttribute(String) is undefined for the type Object** , how do so
I am getting error -**The method getAttribute(String) is undefined for the type Object** , how do so

Time:11-19

System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\eclipse-workspace\\selenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
    
driver.manage().window().maximize();
driver.get("https://www.flipkart.com");
    
List links = driver.findElements(By.tagName("a"));
System.out.println(" Total number of links exist on page" links.size());

int internal_count=0;
int external_count=0;

for(int i=0;i<links.size();i  ) {

    String str1 =links.get(i).getAttribute("href");
    boolean b = str1.startsWith("https://www.flipkart");

    if(b) {
        System.out.println("Internal Link" str1);
        internal_count  ;
    } else {
        System.out.println("External Link" str1);
        external_count  ;
    }
}

CodePudding user response:

This

List links = driver.findElements(By.tagName("a"));

should be

List<WebElement> links = driver.findElements(By.tagName("a"));

Rest your code looks fine.

Code:

@Test
public void testSO() throws InterruptedException {
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.get("https://www.flipkart.com");
    Actions action = new Actions(driver);
    WebDriverWait wait = new WebDriverWait(driver, 30);
    
    List<WebElement> links = driver.findElements(By.tagName("a"));
    System.out.println(" Total number of links exist on page"  links.size());

    int internal_count=0;
    int external_count=0;

    for (WebElement ele : links) {
        try {
            if(ele.getAttribute("href").startsWith("https://www.flipkart")) {
                System.out.println("Internal Link"  ele.getAttribute("href"));
                internal_count  ;
            }
            else {
            System.out.println("External Link"  ele.getAttribute("href"));
            external_count  ;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

Output :

Internal Linkhttps://www.flipkart.com/beardo-hair-thickening-hemp-miracle-oil-100-ml-non-sticky-light-styling-oil-men-pleasant-fragrance-light-daily-strengthening-made-seeds/p/itm093a5e74cee0a?pid=HOLG7ZY3CZ9NZSCH&otracker=hp_bannerads_4_2.bannerAdCard.BANNERADS_Beardo_ZVU5VCL4BXV7
Internal Linkhttps://www.flipkart.com/big-bachat-dhamaal-sale-store?otracker=hp_bannerads_1_2.bannerAdCard.BANNERADS_x_4FZ1XM53CE6H
Internal Linkhttps://www.flipkart.com/mobile-bonanza-november21-82d23e23e-store?param=344&otracker=hp_bannerads_2_2.bannerAdCard.BANNERADS_Cat-Mob-HPW-bonanza_RDICDI1L00IW
Internal Linkhttps://www.flipkart.com/tyy/4io/~cs-estydyrnah/pr?sid=tyy,4io&collection-tab-name=POCO C31&param=3764&sort=price_asc&otracker=hp_bannerads_3_2.bannerAdCard.BANNERADS_Cat-mob-HPW-POCO-C31_23RLED5KYVP9
Internal Linkhttps://www.flipkart.com/beardo-hair-thickening-hemp-miracle-oil-100-ml-non-sticky-light-styling-oil-men-pleasant-fragrance-light-daily-strengthening-made-seeds/p/itm093a5e74cee0a?pid=HOLG7ZY3CZ9NZSCH&otracker=hp_bannerads_4_2.bannerAdCard.BANNERADS_Beardo_ZVU5VCL4BXV7
Internal Linkhttps://www.flipkart.com/big-bachat-dhamaal-sale-store?otracker=hp_bannerads_1_2.bannerAdCard.BANNERADS_x_4FZ1XM53CE6H
Internal Linkhttps://www.flipkart.com/bank-terms-and-conditions-store
Internal Linkhttps://www.flipkart.com/offers-list/top-offers?screen=dynamic&pk=themeViews=Events-Topoffers:Deal-card~widgetType=dealCard~contentType=neo&wid=4.dealCard.OMU_4&otracker=hp_omu_Top+Offers_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_wc_view-all_4
Internal Linkhttps://www.flipkart.com/musical-instruments/keys-synthesizers/musical-keyboards/pr?sid=ypu,nvg,xqg&fm=neo/merchandising&iid=M_82c87020-80c1-4789-9bfb-069611120363_1_372UD5BXDFYS_MC.OOB97OQG0WN4&otracker1=hp_rich_navigation_PINNED_neo/merchandising_NA_NAV_EXPANDABLE_navigationCard_cc_10_L2_view-all&cid=OOB97OQG0WN4&p[]=facets.brand%5B%5D=CASIO&hpid=RwATOSxQ1qqKCH4NsXvc5qp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.E08CO5ZI3RWQ&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_1_4.dealCard.OMU_E08CO5ZI3RWQ_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_1_NA_view-all_4&cid=E08CO5ZI3RWQ
Internal Linkhttps://www.flipkart.com/musical-instruments/keys-synthesizers/musical-keyboards/pr?sid=ypu,nvg,xqg&p[]=facets.discount_range_v1%5B%5D=30%25+or+more&p[]=facets.discount_range_v1%5B%5D=40%25+or+more&p[]=facets.discount_range_v1%5B%5D=20%25+or+more&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.MA7OV7VPYOAB&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_2_4.dealCard.OMU_MA7OV7VPYOAB_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_2_NA_view-all_4&cid=MA7OV7VPYOAB
Internal Linkhttps://www.flipkart.com/musical-instruments/~cs-wg8z12xdtk/pr?sid=ypu&collection-tab-name=Top 100 Musical Instruments &fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.7DWQQRP3RR4F&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_3_4.dealCard.OMU_7DWQQRP3RR4F_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_3_NA_view-all_4&cid=7DWQQRP3RR4F
Internal Linkhttps://www.flipkart.com/furniture/furniture-accessories/home-temple/~cs-g6oe1x4pkp/pr?sid=wwe,q7b,9zz&p[]=facets.price_range.from=Min&p[]=facets.price_range.to=1000&hpid=LAjFz_9NEAXsj-og4Wh6oqp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.3KG9W7QD6EGI&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_4_4.dealCard.OMU_3KG9W7QD6EGI_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_4_NA_view-all_4&cid=3KG9W7QD6EGI
Internal Linkhttps://www.flipkart.com/water-purifiers/~cs-czjgpiv7tz/pr?sid=j9e,abm,i45&p[]=facets.fulfilled_by%5B%5D=Flipkart+Assured&sort=popularity&p[]=facets.price_range.from=4999&p[]=facets.price_range.to=Max&p[]=facets.type%5B%5D=Electrical+%26+Storage&hpid=QuztcqFM-5hkwIeW5VSAXKp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.FCGOUHJTNPZT&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_5_4.dealCard.OMU_FCGOUHJTNPZT_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_5_NA_view-all_4&cid=FCGOUHJTNPZT
Internal Linkhttps://www.flipkart.com/beauty-and-grooming/~cs-enwwn6uk96/pr?sid=g9b&collection-tab-name=Cara Mia Grooming&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.E09D87ZFEODR&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_6_4.dealCard.OMU_E09D87ZFEODR_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_6_NA_view-all_4&cid=E09D87ZFEODR
Internal Linkhttps://www.flipkart.com/furniture/cabinets/kitchen-cabinets/~cs-g6oe1x4pkp/pr?sid=wwe,6by,9dn&sort=popularity&hpid=W2rAJ_wo8Z7M-8NyPRaGlqp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.NSRZGI8QGNLN&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_7_4.dealCard.OMU_NSRZGI8QGNLN_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_7_NA_view-all_4&cid=NSRZGI8QGNLN
Internal Linkhttps://www.flipkart.com/musical-instruments/studiostage-equipment-accessories/microphone/pr?sid=ypu,alc,3d4&p[]=facets.discount_range_v1%5B%5D=30%25+or+more&fm=neo/merchandising&iid=M_e627ea1b-d9b1-4edd-aa1d-b83b01ff8061_2_372UD5BXDFYS_MC.KZXMK6CTEATF&cid=KZXMK6CTEATF&p[]=facets.discount_range_v1%5B%5D=40%25+or+more&p[]=facets.discount_range_v1%5B%5D=50%25+or+more&p[]=facets.discount_range_v1%5B%5D=60%25+or+more&p[]=facets.fulfilled_by%5B%5D=Flipkart+Assured&hpid=QEJRKfD47pPwmcs_kafF5ap7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_4.XYO7BWXT7RSW&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Top+Offers_8_4.dealCard.OMU_XYO7BWXT7RSW_4&otracker1=hp_omu_PINNED_neo/merchandising_Top+Offers_NA_dealCard_cc_8_NA_view-all_4&cid=XYO7BWXT7RSW
Internal Linkhttps://www.flipkart.com/beauty-and-grooming/pr?sid=g9b&p[]=facets.fulfilled_by%5B%5D=Flipkart+Assured&fm=neo/merchandising&iid=M_633a116c-4415-41ab-9491-8a20111baf68_1_372UD5BXDFYS_MC.NJKL2WGZ9KLB&otracker1=hp_rich_navigation_PINNED_neo/merchandising_NA_NAV_EXPANDABLE_navigationCard_cc_1_L2_view-all&cid=NJKL2WGZ9KLB&p[]=facets.brand%5B%5D=HIMALAYA&p[]=facets.discount_range_v1%5B%5D=30%25+or+more&nnc=H4NAXEAJJRPA_AD&otracker=hp_rhs_announcement_1_5.rhsAnnouncement.RHS_ANNOUNCEMENT_H4NAXEAJJRPA
Internal Linkhttps://www.flipkart.com/offers-list/todays-fashion-deals?screen=dynamic&pk=themeViews=LS-Big-Bachat-Topdeals:DD-HP~widgetType=dealCard~contentType=neo&wid=7.dealCard.OMU_6&otracker=hp_omu_Today%27s+Fashion+Deals_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_wc_view-all_6
Internal Linkhttps://www.flipkart.com/clothing-and-accessories/winter-wear/pr?sid=clo,qvw&p[]=facets.ideal_for%5B%5D=Girls&p[]=facets.ideal_for%5B%5D=Boys&p[]=facets.ideal_for%5B%5D=Boys+%26+Girls&p[]=facets.ideal_for%5B%5D=Baby+Boys&p[]=facets.ideal_for%5B%5D=Baby+Girls&p[]=facets.ideal_for%5B%5D=Baby+Boys+%26+Baby+Girls&p[]=facets.price_range.from=Min&p[]=facets.price_range.to=499&parm=2345&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.78WV1FRYA60C&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_1_7.dealCard.OMU_78WV1FRYA60C_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_1_NA_view-all_6&cid=78WV1FRYA60C
Internal Linkhttps://www.flipkart.com/clothing-and-accessories/~cs-tzjb72e1aj/pr?sid=clo&collection-tab-name=Women Ethnic Collection&sort=popularity&p[]=facets.price_range.from=149&p[]=facets.price_range.to=799&hpid=zbZjjUbBXI0EDiDgrAjeVKp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.EYSDGGNPWUTH&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_2_7.dealCard.OMU_EYSDGGNPWUTH_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_2_NA_view-all_6&cid=EYSDGGNPWUTH
Internal Linkhttps://www.flipkart.com/watches/wrist-watches/pr?sid=r18,f13&param=123&p[]=facets.price_range.from=99&p[]=facets.price_range.to=Max&hpid=WdeGhtwd13Uj2HN5GqNkCKp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.RKWUSVMR227W&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_3_7.dealCard.OMU_RKWUSVMR227W_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_3_NA_view-all_6&cid=RKWUSVMR227W
Internal Linkhttps://www.flipkart.com/backpacks/~cs-yqpnjob9z8/pr?sid=reh,4d7,ak9&p[]=facets.fulfilled_by%5B%5D=Flipkart+Assured&p[]=facets.price_range.from=500&p[]=facets.price_range.to=799&hpid=VnFtb8NWuX1GpQJ-FmwgU6p7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.IR402XXGLDXX&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_4_7.dealCard.OMU_IR402XXGLDXX_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_4_NA_view-all_6&cid=IR402XXGLDXX
Internal Linkhttps://www.flipkart.com/mens-footwear/pr?sid=osp,cil&p[]=facets.price_range.from=199&p[]=facets.price_range.to=1000&p[]=facets.brand%5B%5D=United+Colors+of+Benetton&p[]=facets.brand%5B%5D=Bond+Street+By+Red+Tape&p[]=facets.brand%5B%5D=Bata&p[]=facets.brand%5B%5D=Bata+Leisure&p[]=facets.brand%5B%5D=ADIDAS+NEO&p[]=facets.brand%5B%5D=RED+CHIEF&p[]=facets.brand%5B%5D=HUSH+PUPPIES&p[]=facets.brand%5B%5D=Peter+England+PE&p[]=facets.brand%5B%5D=ADIDAS+ORIGINALS&p[]=facets.brand%5B%5D=Converse&p[]=facets.brand%5B%5D=V+Dot+Van+Heusen&p[]=facets.brand%5B%5D=Sole+Threads&p[]=facets.brand%5B%5D=Wildcraft&p[]=facets.brand%5B%5D=Superdry&p[]=facets.brand%5B%5D=REEBOK+CLASSICS&p[]=facets.brand%5B%5D=WROGN&p[]=facets.brand%5B%5D=JACK+%26+JONES&p[]=facets.brand%5B%5D=ALDO&p[]=facets.brand%5B%5D=FRANCO+LEONE&p[]=facets.brand%5B%5D=Allen+Solly&p[]=facets.brand%5B%5D=Spykar&p[]=facets.brand%5B%5D=Gliders+by+Liberty&p[]=facets.brand%5B%5D=Fsports&p[]=facets.brand%5B%5D=Ben+Sherman&p[]=facets.brand%5B%5D=A-HA+By+Liberty&p[]=facets.brand%5B%5D=Lakhani&p[]=facets.brand%5B%5D=Aqualite&p[]=facets.brand%5B%5D=Paragon&p[]=facets.brand%5B%5D=Khadim%27s&p[]=facets.brand%5B%5D=French+Connection&p[]=facets.brand%5B%5D=Roadster&p[]=facets.brand%5B%5D=Mast+%26+Harbour&p[]=facets.brand%5B%5D=Kook+N+Keech&p[]=facets.brand%5B%5D=ether&p[]=facets.brand%5B%5D=Lakhani+Vardaan&p[]=facets.brand%5B%5D=CARLTON+LONDON&p[]=facets.brand%5B%5D=Asics+TIGER&p[]=facets.brand%5B%5D=Attilio&p[]=facets.brand%5B%5D=PROVOGUE&p[]=facets.brand%5B%5D=LEE+COOPER&p[]=facets.brand%5B%5D=WOODLAND&p[]=facets.brand%5B%5D=VANS&p[]=facets.brand%5B%5D=LEVI%27S&p[]=facets.brand%5B%5D=U.S.+POLO+ASSN.&p[]=facets.brand%5B%5D=RED+TAPE&p[]=facets.brand%5B%5D=CROCS&p[]=facets.brand%5B%5D=SPARX&p[]=facets.brand%5B%5D=CLARKS&p[]=facets.brand%5B%5D=INDIGO+NATION&p[]=facets.brand%5B%5D=METRONAUT&p[]=facets.brand%5B%5D=NORTH+STAR&p[]=facets.brand%5B%5D=SAN+FRISSCO&p[]=facets.brand%5B%5D=ARROW&p[]=facets.brand%5B%5D=FLYING+MACHINE&p[]=facets.brand%5B%5D=RUOSH&p[]=facets.brand%5B%5D=PAVERS+ENGLAND&p[]=facets.brand%5B%5D=DIESEL&p[]=facets.brand%5B%5D=CALL+IT+SPRING&p[]=facets.brand%5B%5D=VAN+HEUSEN&p[]=facets.brand%5B%5D=DUCATI&p[]=facets.brand%5B%5D=MERRELL&p[]=facets.brand%5B%5D=TOMMY+HILFIGER&p[]=facets.brand%5B%5D=PARK+AVENUE&p[]=facets.brand%5B%5D=ALBERTO+TORRESI&p[]=facets.brand%5B%5D=AEROPOSTALE&p[]=facets.brand%5B%5D=COOLERS+BY+LIBERTY&p[]=facets.brand%5B%5D=DUKE&p[]=facets.brand%5B%5D=LIBERTY&p[]=facets.brand%5B%5D=ACTION&p[]=facets.brand%5B%5D=PETER+ENGLAND&p[]=facets.brand%5B%5D=Lakhani+touch&p[]=facets.brand%5B%5D=MUFTI&p[]=facets.brand%5B%5D=PEOPLE&p[]=facets.brand%5B%5D=MOCHI&p[]=facets.brand%5B%5D=WOODS&sort=popularity&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.DJCJ9195EBUO&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_5_7.dealCard.OMU_DJCJ9195EBUO_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_5_NA_view-all_6&cid=DJCJ9195EBUO
Internal Linkhttps://www.flipkart.com/clothing-and-accessories/~cs-yzilopt3p8/pr?sid=clo&collection-tab-name=Tops, T-Shirts, Dresses...&p[]=facets.price_range.from=149&p[]=facets.price_range.to=1000&hpid=TWo_EwOlsYzw1DDFcKOQaKp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.TN1CG1EY4CMN&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_6_7.dealCard.OMU_TN1CG1EY4CMN_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_6_NA_view-all_6&cid=TN1CG1EY4CMN
Internal Linkhttps://www.flipkart.com/jewellery/artificial-jewellery/pr?sid=mcr,96v&p[]=facets.price_range.from=Min&p[]=facets.price_range.to=699&p[]=facets.collection%5B%5D=Ethnic&hpid=VKH3yT84bVxY1S5A91lt46p7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.BUOZUKQAL36D&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_7_7.dealCard.OMU_BUOZUKQAL36D_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_7_NA_view-all_6&cid=BUOZUKQAL36D
Internal Linkhttps://www.flipkart.com/sunglasses/pr?sid=26x&marketplace=FLIPKART&p[]=facets.ideal_for%5B%5D=Women&sort=popularity&p[]=facets.ideal_for%5B%5D=Girls&p[]=facets.price_range.from=99&p[]=facets.price_range.to=999&hpid=sBoRpaNyOuh339dVXUhheqp7_Hsxr70nj65vMAAFKlc=&fm=neo/merchandising&iid=M_3b6d0781-2ea7-4fbd-bf4f-8c5323192577_7.JVBKMIXVB2XT&ppt=None&ppn=None&ssid=u5peumxc340000001637319966144&otracker=hp_omu_Today%27s+Fashion+Deals_8_7.dealCard.OMU_JVBKMIXVB2XT_6&otracker1=hp_omu_PINNED_neo/merchandising_Today%27s+Fashion+Deals_NA_dealCard_cc_8_NA_view-all_6&cid=JVBKMIXVB2XT
Internal Linkhttps://www.flipkart.com/brands
Internal Linkhttps://www.flipkart.com/apple-iphone-13-pink-128-gb/p/itm6e30c6ee045d2?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-13-pro-graphite-512-gb/p/itm5c4ef35fbe69f?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-13-pro-max-sierra-blue-128-gb/p/itm5ede69d71530a?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-13-mini-starlight-128-gb/p/itmcb65606f21fd3?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/tv-and-appliances-big-billion-days-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/flipkart-pay-later-emi-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/big-billion-days-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/motor-insurance-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/flipkartquick-hyperlocal-campaign-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/clothing-and-accessories/ed-a-mamma~brand/pr?sid=clo&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/books-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/flipkart-electronics-sale-tv-and-appliances-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/grand-kitchen-sale-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/all-auto-accessories-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/sunglasses/streak-specsmakers~brand/pr?sid=26x&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/q/gold-coins?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/bgm-big-billion-days-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/home-bbd-intriuge-dhamaka-sale-pn-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/plus?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/supercoin?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/covid-insurance-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/helpcentre?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/helpcentre/trackOrder/i/2?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/helpcentre/manageOrder/i/3?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/helpcentre/returnOrder/i/4?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/the-gift-card-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/q/sarees?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/flipkart-axis-bank-credit-card-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/flipkart-pay-later-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/jewellery/pr?sid=mcr&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/watches/pr?sid=r18&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/jewellery/~gold-coins/pr?sid=mcr&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mangalsutra/pr?sid=mcr,96v,t4i,0f4&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/sunglasses/pr?sid=26x&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/sunglasses/mi~brand/pr?sid=26x&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/backpacks/pr?sid=reh,4d7,ak9&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/sunglasses/ray-ban~brand/pr?sid=26x&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-12-white-64-gb/p/itm8b88bdc03cd79?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-12-pro-graphite-512-gb/p/itmdf0ffb4f2150f?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-12-blue-128-gb/p/itm02853ae92e90a?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-y91i-fusion-black-32-gb/p/itmff6vsadyrbauf?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-y11-mineral-blue-32-gb/p/itmb764fb6d6ef60?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-y15-aqua-blue-64-gb/p/itmfgadf77s87w8x?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-y50-pearl-white-128-gb/p/itmd0dcc06ffbe06?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-y12-burgundy-red-64-gb/p/itmfhyjvucp5mueg?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/oppo-reno2-f-lake-green-256-gb/p/itm8413e7eb0b195?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/oppo-a12-blue-32-gb/p/itmfc859cdf39e01?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/oppo-f15-blazing-blue-128-gb/p/itm56d35565691ea?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/oppo-a31-fantasy-white-64-gb/p/itm82e19f459118a?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/samsung-galaxy-a71-prism-crush-blue-128-gb/p/itmb719fd01880e3?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/samsung-galaxy-a51-prism-crush-blue-128-gb/p/itme8079f0fedb33?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/samsung-galaxy-a31-prism-crush-white-128-gb/p/itma110137399bdc?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/realme-x2-pearl-green-64-gb/p/itm75023903eb431?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/realme-5-crystal-purple-32-gb/p/itmfj9twbwfznhyk?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/infinix-hot-8-quetzal-cyan-64-gb/p/itm176568dde7f63?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-11-white-64-gb/p/itm2644c3764fc54?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-11-pro-space-grey-64-gb/p/itm7e24c1c560208?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-11-pro-max-gold-64-gb/p/itm6ef18218efdf6?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mobile-phone-offers-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-x-space-gray-64-gb/p/itmexrgv6hctyrav?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-8-silver-64-gb/p/itmexrgvsw7vedwq?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-7-black-32-gb/p/itmen6daftcqwzeg?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/apple-iphone-6-space-grey-32-gb/p/itmetmh3hfhnxtcj?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/redmi-5a-gold-16-gb/p/itmfy6cg6a5m7mwh?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/4g-mobile-phones-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/nokia-mobile-phones-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/samsung-mobile-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mobiles/apple~brand/pr?sid=tyy,4io&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/oppo-mobile-phones-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/vivo-mobile-phones-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/gopro-hero-sports-action-camera/p/itmf3s4abpfgawhc?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/cameras/nikon~brand/pr?sid=jek,p31&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/cameras/canon~brand/pr?sid=jek,p31&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/q/sony-cameras?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/q/canon-dslr-cameras?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/cameras/dslr-mirrorless/nikon~brand/pr?sid=jek,p31,trv&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/microsoft-surface-go-pentium-gold-4-gb-64-gb-emmc-storage-windows-10-home-s-mode-1824-2-1-laptop/p/itmfb6pyegb9vgck?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/microsoft-surface-go-pentium-gold-8-gb-128-gb-ssd-windows-10-home-s-mode-1824-2-1-laptop/p/itmfb6pyjzy9y8n4?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/apple~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/acer~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/lenovo~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/dell~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/asus~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/hp~brand/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/gaming/gaming-laptops/pr?sid=4rr,tz1&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/laptops/~2-in-1-laptops/pr?sid=6bo,b5g&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/computers/~business-laptops/pr?sid=6bo&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/tv-and-appliances-big-billion-days-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/motorola~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/q/redmi-smart-tvs?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/oneplus~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/launching-realme-sled-4k-smart-tv-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mi-led-smart-tv-4x-108-cm-43/p/itmab87244d2fead?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mi-led-smart-tv-4a-100-cm-40/p/itmaaa9224388773?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mi-led-smart-tv-4x-163-9-cm-65/p/itm4b78549a6a25e?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/samsung-7-in-1-80cm-32-inch-hd-ready-led-smart-tv/p/itmfga98hypx8wzc?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/lg~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/television-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/sony~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/samsung~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/mi-led-smart-tv-4a-pro-123-2-cm-49/p/itmfcp72rrahu6vf?pid=TVSFCP72GZYESDHF&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/android-tv-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/iffalcon-by-tcl-smart-tvs-launch-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/televisions/mi~brand/pr?sid=ckf,czl&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/tv-and-appliances-big-billion-days-store?otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/washing-machines/pr?sid=j9e,abm,8qx&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/refrigerators/pr?sid=j9e,abm,hzg&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/air-conditioners/pr?sid=j9e,abm,c54&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/air-fryers/pr?sid=j9e,m38,j1e&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/appliance-parts-accessories/pr?sid=j9e,m38,vli&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/bread-makers/pr?sid=j9e,m38,y3d&otracker=undefined_footer_footer
Internal Linkhttps://www.flipkart.com/cake-maker/pr?sid=j9e,m38,z9o&otracker=undefined_footer_footer

CodePudding user response:

As @vincrichaud correctly pointed out in the comment, as you declared the list links it had no generics defined, so Java consider its elements type as Object. Moving forward, when you do:

links.get(i).getAttribute("href");

The objects are iterated which have no method as getAttribute(). Hence you see the error:

The method getAttribute(String) is undefined for the type Object

Solution

While declaring the list include the generics type as WebElement as follows:

List<WebElement> links = driver.findElements(By.tagName("a"));
  • Related