1

I m trying to click on the dropdown menu item and i am able to select the dropdown and the menu item but instead of clicking on item the click is going to the element right under it.

Before the dropdown code, I am executing the following code to close the pop up window

            driver.switchTo().window(windowHandle).close();
            driver.switchTo().window(driver.getWindowHandles().toArray()[0].toString());

I think this might have something to do with click going to wrong item

JAVA CODE

driver.findElement(By.xpath("//*[@id='ext-gen32']/table/tbody/tr[2]/td[2]/em[@class='x-btn-split']")).click();
org.openqa.selenium.interactions.Actions action = new org.openqa.selenium.interactions.Actions(driver);
boolean ele = isElementPresent(By.xpath(Configurations.getServiceLocator("sc.cases.arrow")));
String arrow = "//*[@id='ext-gen32']";
WebElement elem = driver.findElement(By.xpath(arrow));
action.moveToElement(elem, 235, 17);
action.click().perform();

List<WebElement> sideBarElements = getElements(By
        .cssSelector("a.x-menu-item"));

for (WebElement element : sideBarElements) {
    if (element.getText().equalsIgnoreCase(“Lookup Contact”)) {
        element.click();
        break;
    }
}

HTML

<div id="servicedesk" class=" x-border-panel x-border-layout-ct" style="left: 0px; top: 65px; width: 1680px; height: 553px;">
    <div id="navigatortab" class=" x-plain undefined sd_nav_tabpanel x-border-panel" style="left: 0px; top: 0px; width: 1680px;">
        <div class="support-servicedesk-navigator" id="ext-gen32" style="background: rgb(229, 231, 233);">
            <table id="ext-comp-1006" cellspacing="0" class="x-btn support-servicedesk-sb Custom9Mru mruIcon support-servicedesk-sbactive x-btn-noicon" style="width: 250px; height: 26px;">
                <tbody class="x-btn-small x-btn-icon-small-left">
                    <tr>
                        <td class="x-btn-tl"><i>&nbsp;</i></td>
                        <td class="x-btn-tc"></td>
                        <td class="x-btn-tr"><i>&nbsp;</i></td>
                    </tr>
                    <tr>
                        <td class="x-btn-ml"><i>&nbsp;</i></td>
                        <td class="x-btn-mc"><em class="x-btn-split" unselectable="on" id="ext-gen92"><button type="button" id="ext-gen33" class=" x-btn-text"><div class="mruIcon"></div><span>Lookup Contact</span></button></em></td>
                        <td class="x-btn-mr"><i>&nbsp;</i></td>
                    </tr>
                    <tr>
                        <td class="x-btn-bl"><i>&nbsp;</i></td>
                        <td class="x-btn-bc"></td>
                        <td class="x-btn-br"><i>&nbsp;</i></td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="x-plain-header sd_primary_tabstrip x-unselectable" id="ext-gen22" style="background: rgb(229, 231, 233); width: 1680px;">
            <div class="x-tab-tabmenu-right" id="ext-gen36"></div>
            <div class="x-tab-strip-wrap" id="ext-gen25" style="width: 1408px; left: 250px;">
                <ul class="x-tab-strip x-tab-strip-top" id="ext-gen27" style="background: rgb(229, 231, 233);">
                    <li class=" x-tab-strip-active" id="navigatortab__ext-comp-1004" style="display: none;">
                        <a class="x-tab-strip-close" id="ext-gen30"></a><a class="x-tab-right" href="#" id="ext-gen31"><em class="x-tab-left"><span class="x-tab-strip-inner"><span class="x-tab-strip-text "></span></span></em></a></li>
                    <li class="add-tab-btn" id="navigatortabaddTabButton">
                        <a class="x-tab-strip-close"></a><a class="x-tab-right" href="#" id="ext-gen35" style="padding-left: 6px;"><em class="x-tab-left" id="ext-gen34" style="padding-right: 6px;"><span class="x-tab-strip-inner"><span class="x-tab-strip-text "></span></span></em></a></li>
                    <li class="x-tab-edge" id="ext-gen28"><span class="x-tab-strip-text">&nbsp;</span></li>
                    <div class="x-clear" id="ext-gen29"></div>
                </ul>
            </div>
            <div class="x-tab-strip-spacer" id="ext-gen26"></div>
        </div>
        <div class="x-plain-bwrap" id="ext-gen23">
            <div class="x-plain-body sd_nav_tabpanel_body x-tab-panel-body-top" id="ext-gen24" style="width: 1680px; height: 521px;">
                <div id="ext-comp-1004" class="" style="width: 1680px; height: 521px;">
                    <iframe id="ext-comp-1005" name="ext-comp-1005" frameborder="0" allow="camera *; geolocation *; microphone *" src="/servlet/servlet.Integration?lid=01rd00000007Ruf&amp;ic=1&amp;linkToken=VmpFPSxNakF4T1Mwd015MHdNVlF3TkRveE56bzBNQzR5T0RKYSx2Sm81dVNhWlBVLTRMQlMtVW01c3J1LFlXWmtNR0po&amp;isdtp=nv&amp;nonce=182e776daf5f434d79f1d86ca453d03c6e18161b87fd78f9c08805c6dbd4ab4b&amp;sfdcIFrameOrigin=https%3A%2F%2Fintuit.my.salesforce.com" style="width: 1680px; height: 521px;"></iframe>
                </div>
            </div>
        </div>
    </div>
</div>

Dropdown Html

<div id="navigator-sbmenu" class="x-menu x-menu-floating x-layer x-hide-offsets" style="position: absolute; z-index: 15000; visibility: hidden; left: -10000px; top: -10000px; width: 250px;">
    <a class="x-menu-focus" href="#" onclick="return false;" tabindex="-1" id="ext-gen93"></a>
    <ul class="x-menu-list" id="ext-gen94" style="height: 392px;">
        <li id="x-menu-el-nav-tab-0" class="x-menu-list-item">
            <a id="nav-tab-0" class="x-menu-item Custom103Mru userDefinedMRU 01541000002eEOg sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="https://intuit--c.na75.content.force.com/servlet/servlet.ImageServer?id=01541000002eEOg&amp;oid=00DE0000000a8TL&amp;lastMod=1504832300000" class="x-menu-item-icon Custom103Mru userDefinedMRU 01541000002eEOg mruIcon" id="ext-gen96"><span class="x-menu-item-text" id="ext-gen97">My Clients</span></a>
        </li>
        <li id="x-menu-el-nav-tab-1" class="x-menu-list-item">
            <a id="nav-tab-1" class="x-menu-item Custom91Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom91Mru mruIcon" id="ext-gen98"><span class="x-menu-item-text" id="ext-gen99">Team Summary</span></a>
        </li>
        <li id="x-menu-el-nav-tab-2" class="x-menu-list-item">
            <a id="nav-tab-2" class="x-menu-item Custom153Mru userDefinedMRU 01541000002eERQ sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="https://intuit--c.na75.content.force.com/servlet/servlet.ImageServer?id=01541000002eERQ&amp;oid=00DE0000000a8TL&amp;lastMod=1504833236000" class="x-menu-item-icon Custom153Mru userDefinedMRU 01541000002eERQ mruIcon" id="ext-gen100"><span class="x-menu-item-text" id="ext-gen101">Calendar</span></a>
        </li>
        <li id="x-menu-el-nav-tab-3" class="x-menu-list-item">
            <a id="nav-tab-3" class="x-menu-item caseMru standardObject sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon caseMru standardObject mruIcon" id="ext-gen102"><span class="x-menu-item-text" id="ext-gen103">Cases</span></a>
        </li>
        <li id="x-menu-el-nav-tab-4" class="x-menu-list-item">
            <a id="nav-tab-4" class="x-menu-item Custom37Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom37Mru mruIcon" id="ext-gen104"><span class="x-menu-item-text" id="ext-gen105">Lookup Online Account</span></a>
        </li>
        <li id="x-menu-el-nav-tab-5" class="x-menu-list-item support-servicedesk-sbmenuitemselected">
            <a id="nav-tab-5" class="x-menu-item Custom9Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom9Mru mruIcon" id="ext-gen106"><span class="x-menu-item-text" id="ext-gen107">Lookup Contact</span></a>
        </li>
        <li id="x-menu-el-nav-tab-6" class="x-menu-list-item">
            <a id="nav-tab-6" class="x-menu-item Custom67Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom67Mru mruIcon" id="ext-gen108"><span class="x-menu-item-text" id="ext-gen109">Order Search</span></a>
        </li>
        <li id="x-menu-el-nav-tab-7" class="x-menu-list-item">
            <a id="nav-tab-7" class="x-menu-item contactMru standardObject sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon contactMru standardObject mruIcon" id="ext-gen110"><span class="x-menu-item-text" id="ext-gen111">Contacts</span></a>
        </li>
        <li id="x-menu-el-nav-tab-8" class="x-menu-list-item">
            <a id="nav-tab-8" class="x-menu-item Custom123Mru userDefinedMRU 01541000001GoUv sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="https://intuit--c.na75.content.force.com/servlet/servlet.ImageServer?id=01541000001GoUv&amp;oid=00DE0000000a8TL&amp;lastMod=1484285285000" class="x-menu-item-icon Custom123Mru userDefinedMRU 01541000001GoUv mruIcon" id="ext-gen112"><span class="x-menu-item-text" id="ext-gen113">Lookup EFE</span></a>
        </li>
        <li id="x-menu-el-nav-tab-9" class="x-menu-list-item">
            <a id="nav-tab-9" class="x-menu-item Custom90Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom90Mru mruIcon" id="ext-gen114"><span class="x-menu-item-text" id="ext-gen115">My Scorecard</span></a>
        </li>
        <li id="x-menu-el-nav-tab-10" class="x-menu-list-item">
            <a id="nav-tab-10" class="x-menu-item Custom50Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom50Mru mruIcon" id="ext-gen116"><span class="x-menu-item-text" id="ext-gen117">Learning Dashboard</span></a>
        </li>
        <li id="x-menu-el-nav-tab-11" class="x-menu-list-item">
            <a id="nav-tab-11" class="x-menu-item Custom15Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom15Mru mruIcon" id="ext-gen118"><span class="x-menu-item-text" id="ext-gen119">Employee Profile Updater</span></a>
        </li>
        <li id="x-menu-el-nav-tab-12" class="x-menu-list-item">
            <a id="nav-tab-12" class="x-menu-item Custom20Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom20Mru mruIcon" id="ext-gen120"><span class="x-menu-item-text" id="ext-gen121">Bulk Policy Removal</span></a>
        </li>
        <li id="x-menu-el-nav-tab-13" class="x-menu-list-item">
            <a id="nav-tab-13" class="x-menu-item Custom39Mru sd-nav-menu-item" hidefocus="true" unselectable="on" href="#"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-menu-item-icon Custom39Mru mruIcon" id="ext-gen122"><span class="x-menu-item-text" id="ext-gen123">Lookup Online TTA Account</span></a>
        </li>
    </ul>
</div>
  • Please give us your locator and your html – Alexey R. Feb 25 at 17:13
  • Uploaded the html and java code – Twinkle Notna Feb 26 at 4:58
0

I am not sure what your element or page is look like but if there is a dropdown you should try select class of selenium webdriver in automation testing services https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html

Select class is for dealing with dropdowns.

  • The code is working fine up to the last line. SideBarElements is getting initialized with all menu items and it is getting into the if condition too but the click statement is not working – Twinkle Notna Feb 27 at 10:15
  • Code was working fine before adding the code of closing the popup window – Twinkle Notna Feb 27 at 10:27
  • try to use Actions class for clicking on element, if that doesn't work use javascript for clicking on element. – Vishal Mar 1 at 12:08
  • Actions are not working – Twinkle Notna Mar 7 at 5:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.