0

I have the following area on the HTML page:

<div class="t2-selector">  
    <div class="">  
        USA  
        <div>  
            <div>  
                <div>  
                    <div class="selected" asset-id="129">Google</div>  
                    <div asset-id="130">Microsoft</div>  
                    <div asset-id="126">Apple</div>  
                </div>  
           </div>  
       </div>  
</div>  
<div class="inactive">  
    Europe  
    <div>  
        <div>  
            <div>  
                <div class="inactive" asset-id="127">BT</div>  
            </div>  
        </div>  
   </div>  
</div>  
<div class="">  
    Currencies  
    <div>  
        <div>  
            <div>  
                <div asset-id="135">EUR/USD</div>  
                    <div asset-id="136" class="">GBP/USD</div>  
                    <div asset-id="137" class="">USD/JPY</div>  
                    <div asset-id="138" class="selected">USD/CHF</div>  
                    <div asset-id="139">AUD/USD</div>  
                    <div asset-id="140">USD/CAD</div>  
                </div>  
            </div>  
       </div>  
</div>  

So I need to select desired element from one of the groups (that should not be inactive, OK).
When I'm selecting a group nothing occurs, no error and I don't see the the selected group opens. Even for a moment.
But when I'm trying to select an element in previously clicked group I receive

org.openqa.selenium.ElementNotVisibleException: element not visible  

error.
So I understand that in the moment I'm clicking on desired element it is not visible since the group not appears open.
But why?
And what can I do to resolve this problem?
Currently I'm using following code:

String selectedGroup = getValue("group",'o');  
    String xpath1 = "//div[contains(text(),'" + selectedGroup + "')]";  
    driver.findElement(By.xpath(xpath1)).click();  
    webElement = driver.findElement(By.xpath(xpath1));  
    String className = webElement.getAttribute("class");  
    if(className.contentEquals("inactive"))  
        throw new ElementInactiveException("Selected group appears inactive. Exiting the test");  

    String optionAssetID = getValue("assetID",'o');  
    String xpath2 ="//div[@asset-id='" + optionAssetID + "']";  

    driver.findElement(By.xpath(xpath2)).click();  

the error occur on the following line:

driver.findElement(By.xpath(xpath2)).click();  

When clicking on a Group or hovering over it it looks in the following way:
As you can see from the code the selected / opened group receives "group-visible" class parameter.

When clicked on a Group or hovered over it it looks so:

4
  • At which line in your code do you receive this error? Commented Feb 8, 2016 at 18:07
  • driver.findElement(By.xpath(xpath2)).click(); Commented Feb 8, 2016 at 18:09
  • You mention about group not opening. What are the groups here. It might be better to paste a screenshot - obviously there is some scripting happening that we cannot see. Commented Feb 8, 2016 at 18:13
  • Screenshot and additional explanations are added Commented Feb 8, 2016 at 18:27

2 Answers 2

3

You can hover over the drop down to open it and then click on your element

// simulate mouse movement to the dropdown 
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath(xpath1))).perform();

// wait for the element to be visible before clicking on it
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(xpath2)).click();
Sign up to request clarification or add additional context in comments.

Comments

1

You can also try to click using JavascriptExecutor

WebElement element= driver.findElement(By.xpath("Your Xpath"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

Hope it will help you :)

1 Comment

Thank you very much for the answer. I will try this when I'm back to the work. Currently I'm ill at home :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.