java - Automating Combo Box (drop down + checkbox) using Selenium -
i trying automate drop down in website naukri.com. drop down consists of multi select check-boxes. how can automate using selenium web driver?
the structure of drop list is:
<div class="ddwrap"> <ul class="ddsearch"> <li class="tagit" data-id="tg_indcja_a8_a"> <span class="tagtxt">accounting , finance</span> <span class="dcross"></span> </li> <li class="frst" style="float: left;"> <input id="cjaind" class="srchtxt" type="text" placeholder="" name="" autocomplete="off" style="width: 30px;"> <input id="hid_indcja" type="hidden" name="indtype" value="["8"]"> </li> </ul> </div>
can me regarding this?
check out code below, navigates concerned form, opens dropdown of "industry" , selects 2 checkboxes: 'accounting , finance' , 'government , defence':
webdriver driver = new firefoxdriver(); //opening firefox instance driver.manage().window().maximize(); //maximizing window driver.manage().timeouts().implicitlywait(20, timeunit.seconds); //giving implicit timeout of 20 seconds driver.get("http://www.naukri.com/"); //since there 2 windows popping up, hence switching , closing unnecessary window. set<string> windows = driver.getwindowhandles(); iterator iter = windows.iterator(); string parentwindow = iter.next().tostring(); string childwindow = iter.next().tostring(); driver.switchto().window(childwindow); driver.close(); driver.switchto().window(parentwindow); //hovering on "jobs" actions act = new actions(driver); webelement jobs = driver.findelement(by.xpath("//ul[@class='midsec menu']//div[.='jobs']")); act.movetoelement(jobs).build().perform(); //clicking on "advance search" webelement adv_search = driver.findelement(by.xpath("//ul[@class='midsec menu']/li[1]//a[.='advanced search']")); act.movetoelement(adv_search).click().perform(); //clicking on industry dropdown driver.findelement(by.xpath("//div[@class='ddinputwrap']/input[contains(@placeholder,'select industry')]")).click(); //selecting checkbox containing text "accounting" driver.findelement(by.xpath("//ul[@class='chkboxenb']//a[contains(text(),'accounting')]")).click(); //selecting checkbox containing text 'government' driver.findelement(by.xpath("//ul[@class='chkboxenb']//a[contains(text(),'government')]")).click();
Comments
Post a Comment