Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is the HTML code:

<ul id="personalBar">
    <li id="upload" style="display:none;"></li>
    <li id="personal">
        <span class="translate"></span>
        <span id="userName">qaadmin</span>
        <div id="dropDownArrow"></div>
        <ul>
            <li id="pendingActivities" class="translate" onclick="eCommon.helper.viewAllPendingActivities()" translatekey="MANAGE_STORE">Manage Store</li>
            <li class="translate" onclick="eCommon.helper.outSourceViewReports()" translatekey="UM_REPORT_MENU">Reports</li>
            <li id="learnMore" class="translate" onclick="eCommon.helper.outSourceLearnMore()" translatekey="BANNER_THIRD_MSG">Learn more about einstein™</li>
            <li id="DownloadEinstein" class="translate" onclick="eCommon.helper.outSourceLearnMore()" translatekey="BANNER_FOURTH_MSG">Download the einstein™ World app.</li>
            <li class="translate" onclick="location.reload();" translatekey="CREATE_EINSTEIN_ACIVITIES">Create einstein™ Activities</li>
            <li class="translate" onclick="eCommon.helper.outSourceGetEinsteinActivities()" translatekey="GET_EINSTEIN_ACTIVITIES">Get einstein™ Activities</li>
            <li class="translate" onclick="eCommon.helper.outSourceManageYourEinsteinAccount()" translatekey="MANAGE_YOUR_EINSTEIN_ACCOUNT">Manage your einstein™ Account</li>
            <li id="logOut" class="translate" onclick="am.UserManagement.doLogOut(false)" translatekey="LOGOUT">Logout</li>
        </ul>
    </li>
</ul>  

The amount of items in the list varies according to users privileges so each element number in the list is not fixed.

The list is normally closed and it is opened only by clicking on it. So:

Select dropdown = new Select(driver.findElement(By.id("personalBar")));
dropdown.selectByVisibleText("Get einstein™ Activities");  

Presents error:

org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "ul"

When trying this:

driver.findElement(By.xpath("//li[contains(text(),'Manage your einstein™ Account')][@class='translate']")).click();  

It fails with:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Following should help -

driver.findElement(By.id('personal')).findElement(By.id('dropDownArrow')).click()
driver.findElement(By.xpath("//li[contains(text(),'Manage your einstein™ Account')][@class='translate']")).click();  
share|improve this answer
    
And this worked! –  Eliyahu yesterday

First of all, you cannot approach ul -> li with the Select abstraction - it was designed to work with select -> option.

You second approach fails since you first need to click on ul to open up the list:

WebElement personalList = driver.findElement(By.cssSelector("ul#personalBar li#personal ul"));
personalList.click();

personalList.findElement(By.xpath("//li[contains(text(),'Manage your einstein™ Account')][@class='translate']")).click();  

This is the general idea - first open up the list, then click an item - I might not be accurate in the code and details since I cannot reproduce the problem and test the proposal.

share|improve this answer
    
I just tried this. It gives the error: –  Eliyahu yesterday
    
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with –  Eliyahu yesterday
    
@Eliyahu it could be that you need to first click the outer ul: driver.findElement(By.id("personalBar")).click();. –  alecxe yesterday
    
Thank you @alecxe! I will think about both these answers some more, but currently I accept the second one –  Eliyahu yesterday
    
@Eliyahu sure, this is not a problem at all. What is important is that you've solved it here and you've learned something new. I would've upvoted Vikas's answer if it would contain not only the code, but some more explanation about the options you've tried and about the one that was proposed in the answer. (meta.stackexchange.com/questions/148272/…) Happy seleniuming! –  alecxe yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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