Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

selenium - I would like to select a DropDown from a list but HTML don't have select Tag I am not sure should i use Select class or what

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...