Selenium Web Driver - Span Div CSS dropdownframe - Unable to click the element

635 views Asked by At

I have a complex epiphany web application which is only IE compatible. Here are the sequence of actions on the UI:

The page has multiple frames, out of which there is a Button which when clicked on presents a set of menu options. And the HTML for them is as below :

<div class="FWDropdownMenu" id="test_dropdown">
<div class="DropdownMenuFrame">
<table>
<tbody>
<tr>
<td>
<span class="eABCD" id="e1">
<div class="DropdownMenuItem" id="test2_dropdown" onclick=return eTop.Fire(1,this,event)">
<table>
<tbody>
<tr>
<td>
<div>Option 1</div>
</td>
</tbody>
</table>
</div>

I want to click on Option 1, so i was using this to locate the element :

List<WebElement> options = driver.findElements(By.tagName("table")
                            .tagName("td").id("e1"));    

The Webdriver is able to get the element, but not able to click on it. I was getting error as element not visible, but even when the options are presented on screen through click on menu options, i am still not able to click it.

Any thoughts/suggestions?

2

There are 2 answers

1
Priyanshu On

For me it seems, you haven't used correct element locator. As per you question you want to click on Option 1 and you are selecting element by id e1. which will click on below html element

<span class="eABCD" id="e1">

I'd prefer to use simple locator like this:

driver.findElement(By.xpath("//div[contains(text(),'Option 1')]")).click();

0
Vall On

I found a way. Posting here as it might help anyone in future :

WebElement element = driver.findElement(By.id("test2_dropdown"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

This method uses javascript to click the button. Due to the design of my application, i couldnt click the element through selenium but using internal javascript, i was able to accomplish the task successfully.

Thanks to Stackoverflow!!