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

前端 未结 2 2027
广开言路
广开言路 2020-12-12 03:22

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

相关标签:
2条回答
  • 2020-12-12 04:03

    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();
    
    0 讨论(0)
  • 2020-12-12 04:12

    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;
        }
    }
    
    0 讨论(0)
提交回复
热议问题