我想從列表中選擇一個DropDown,但是HTML沒有選擇標簽,我不確定我應該使用Select類還是其他類。
要選擇從一個值DropDown,你必須先 在WebElement ,然后選擇 您可以使用下面的代碼塊:
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; }}解決方法
我是selenium的新手,我想執行一個簡單的任務,我想從選項卡中選擇一個下拉菜單,并且我已使用“http://www.spicejet.com/”作為參考。網頁spicejet.com中有一個“附加”標簽,其中包含“下拉”值,我想從列表中選擇任意一個值。HTML代碼沒有select標記,因此Select類沒有給我適當的結果。
這是HTML代碼:
<a href='javascript:void(0);' class=''>Add-Ons<span class='rightarrowclass'> </span><span class='rightarrowclass'> </span></a><li><a href='http://www.aoyou183.cn/wenda/SpiceClubMembershipOffer.aspx'>SpiceClub Membership Offer</a></li><li id='ctl00_lblSpiceClublink'><a href=’javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$lblSpiceClub','',false,'SpiceClub.aspx',true))’>SpiceCash/SpiceClub</a></li><li><a >SpiceCash Topup </a></li><a >SpiceMax </a>
請幫助我,讓我知道如何前進。
相關文章:
