Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
973 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...