使用Selenium WEBdriver克隆UL标签

时间:2015-12-09 08:54:47

标签: selenium-webdriver

我有一个带有UL标签的HTML代码,我想点击UL标签管理 - >使用Selenium Webdriver的频道。要做到这一点,我已经在java中编写了下面的代码,但它没有工作,事实上没有错误抛出,但页面正在打开。请帮忙。

HTML

<ul class="adb-primary_nav--items adb-layout-default">
                <li class="adb-primary_nav--item">
                    <a class="adb-primary_nav--link en" href="../">
                        <img class="adb-primary_nav--image" src="https://d33na3ni6eqf5j.cloudfront.net/marketplace_logo/img1474715110198223685.png?7ef040694410736c21450bea763bb661" alt="Vodafone Group">

                    </a>
                </li>
                <li class="adb-primary_nav--item">
                    <a class="adb-primary_nav--link" id="myapps" href="../myapps">
                        MyApps
                    </a>
                </li>
                <li class="adb-primary_nav--item">
                    <a class="adb-primary_nav--link" id="shop" href="../home">
                        Marketplace
                    </a>
                </li>

                    <li class="adb-primary_nav--item"><a class="adb-primary_nav--link" id="developer" href="../cms/home">Developer</a></li>

                <li class="adb-primary_nav--item js-drainable-menu">
                    <div class="adb-context_menu adb-js-context_menu">
                        <a id="manage" class="adb-context_menu--trigger adb-js-context_menu--trigger adb-primary_nav--link admin-item selected" role="button" tabindex="0">Manage</a>
                        <div class="adb-container adb-context_menu--menu adb-js-context_menu--menu" role="menu">
                            <ul class="adb-stack">


                                    <li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content" href="../corporate/home">Corporate</a></li>


                                    <li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content selected" href="./marketplace">Channel</a></li>



                                    <li class="adb-stack--item"><a class="adb-link__option adb-stack--item_content" id="account" href="../account/home">Account</a></li>

                            </ul>
                        </div>
                    </div>
                </li>

                <li class="adb-primary_nav--item adb-primary_nav--item__right">
                    <div class="adb-context_menu adb-js-context_menu" data-placement="right">
                        <a class="adb-context_menu--trigger adb-js-context_menu--trigger adb-primary_nav--link" role="button" tabindex="0">testchannel user</a>
                        <div class="adb-container adb-context_menu--menu adb-js-context_menu--menu" role="menu">
                            <ul class="adb-stack">

                                    <li class="adb-stack--item">
                                        <a class="adb-link__option adb-stack--item_content" id="myProfile" href="../profiles/5944276">My Profile</a>
                                    </li>


                                    <li class="adb-stack--item">
                                        <a class="adb-link__option adb-stack--item_content" id="myCompany" href="../companies/219288">My Company</a>
                                    </li>

                                <li class="adb-stack--item">
                                    <a class="adb-link__option adb-stack--item_content" id="mySettings" href="../settings">My Settings</a>
                                </li>
                                <li class="adb-stack--item">
                                    <a class="adb-link__option adb-stack--item_content" id="logout" href="../logout">Logout</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </li>
            </ul>

Java代码

Configuration_file var = new Configuration_file();

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\gur29175\\workspace\\SAAS\\jars\\chromedriver.exe");

        WebDriver firefox_dri = new ChromeDriver();
        firefox_dri.get(var.env_URL + "/home");
        firefox_dri.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);

        firefox_dri.findElement(By.cssSelector("a:(*'Manage'*)")).click(); 
        firefox_dri.findElement(By.cssSelector("a:(*'Channel'*)")).click(); 

4 个答案:

答案 0 :(得分:0)

driver.findElement(By.xpath(&#34; //一个[@id =&#39;管理&#39;]&#34))。单击() driver.findElement(By.xpath(&#34; // UL [@class =&#39; ADB堆叠&#39;] /锂[2]&#34))。单击()

答案 1 :(得分:0)

如果是列表框,则需要获取元素列表并迭代它以选择所需元素。 请通过下拉菜单分享页面的屏幕截图。将能够为您提供代码指南。

答案 2 :(得分:0)

您可以替换

firefox_dri.findElement(By.cssSelector("a:(*'Manage'*)")).click(); 
firefox_dri.findElement(By.cssSelector("a:(*'Channel'*)")).click(); 

firefox_dri.findElement(By.linkText("Channel")).click();

答案 3 :(得分:0)

试试吧

//ul[@class='adb-stack']/li[@class='adb-stack--item']/a[contains(text(),'Corporate')].click();