Eliyahu Eliyahu - 3 months ago 19
Java Question

How to access invisible Unordered List element with Selenium WebDriver using Java

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

Answer

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();  
Comments