为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用Selenium Webdriver与List <WebElement>结合使用

如何使用Selenium Webdriver与List <WebElement>结合使用

12345678_0001 2021-05-05 17:34:12
我已经使用ArrayList和HashSet编写了以下代码。但是哈希集无法按预期工作,这意味着它不会删除重复的项目。但哈希集不允许重复。**HTML** code<HTML>        <BODY>        <select id= 'WesInn'>        <option value = 'idli'> IDLI</option>        <option value = 'vada'> VADA</option>        <option value = 'sambhar'> SAMBHAR</option>        <option value = 'Manchurian'> MACHURIAN</option>        <option value = 'idli'> IDLI</option>        <option value = 'sambhar'> SAMBHAR</option>        <option value = 'Tea'> TEA</option>        </select>        </body>        </html>public class Assgn_DropDownAsc {    //static String text;    public static void main(String[] args) throws InterruptedException {        System.setProperty("webdriver.chrome.driver","./drivers/chromedriver.exe");        WebDriver driver = new ChromeDriver();        driver.get("C:\\Users\\admin\\Desktop\\New folder/Dropdown.html");        List list = new ArrayList ();        LinkedHashSet hs = new LinkedHashSet();         Adding ArrayList elements to the HashSet         //in order to remove the duplicate elements and          //to preserve the insertion order.        hs.addAll(list);        //System.out.println(hs);        //Removing ArrayList elements        hs.clear();        System.out.println(hs);        System.out.println(list);        //Adding LinkedHashSet elements to the ArrayList        hs.addAll(list);        //System.out.println(alloptions.size());        System.out.println(list);}}输出:[IDLI VADA SAMBHAR MACHURIAN IDLI SAMBHAR TEA]
查看完整描述

2 回答

?
开心每一天1111

TA贡献1836条经验 获得超13个赞

如果您存储的是输出中提到的String,则程序运行正常,看起来您正在打印列表而不是hashSet-更改System.out.println(list);System.out.println(hs);

仅在存储类的对象的情况下才重要,在这种情况下,应该正确重写equals()和hashCode()方法以使用hashSet。


查看完整回答
反对 回复 2021-05-19
  • 2 回答
  • 0 关注
  • 251 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信