0

I am new to selenium and i would like to perform a simple task I want to select a drop-down from a tab and i have used "http://www.spicejet.com/" as an Reference. There is a Tab "Add-On" in webpage spicejet.com and it contains Drop Down value i would like to select any one value from the list. HTML code don't have select tag so Select class not giving me appropriate result.

Here is the HTML code:

<a href="javascript:void(0);" id="highlight-addons" class="">Add-Ons<span class="rightarrowclass">&nbsp;</span><span class="rightarrowclass">&nbsp;</span></a>
<li><a href="SpiceClubMembershipOffer.aspx">SpiceClub Membership Offer</a></li>
<li id="ctl00_lblSpiceClublink">
                                                <a id="ctl00_lblSpiceClub" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$lblSpiceClub", "", false, "", "SpiceClub.aspx", false, true))'>SpiceCash/SpiceClub</a></li>
<li><a href="http://book.spicejet.com/SpiceMoneyTopup.aspx">SpiceCash Topup </a></li>
<a href="http://book.spicejet.com/RetrieveBooking.aspx?AddSeat=true">SpiceMax </a>

Please help me let me know how to move forward.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

Its not a dropdown. It a menu, You can use Actions class to select the sub-menu you want. use below code :

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id("highlight-addons"))).clickAndHold(driver.findElement(By.xpath("//li/a[contains(text(),'SpiceMax')]"))).click().build().perform();
NarendraR
  • 7,577
  • 10
  • 44
  • 82
  • actually its not working, System.setProperty("webdriver.chrome.driver","D:\\chromegecko\\chromedriver.exe\\"); WebDriver driver= new ChromeDriver(); driver.get("http://www.spicejet.com/"); driver.manage().window().maximize(); Actions action = new Actions(driver); action.moveToElement(driver.findElement(By.id("highlight-addons"))).clickAndHold(driver.findElement(By.xpath("//li/a[contains(text(),'SpiceMax')]"))).click().build().perform(); Thread.sleep(5000); } } – Akula Bhaskar Dec 15 '17 at 10:03
0

To select a value from the DropDown, you have to first Mouse Hover the WebElement ADD-ONS, then to select SpiceClub Membership Offer you can use the following code block :

WebElement elem = driver.findElement(By.xpath("//a[@id='highlight-addons']"));
Actions action = new Actions(driver);
action.moveToElement(elem).perform();
List<WebElement> items = driver.findElements(By.xpath("//ul[@class='add-ons-tab']/li/a"));
for(WebElement myitem:items)
{
    if(myitem.getAttribute("innerHTML").contains("Membership"))
    {
        myitem.click();
        break;
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352