2

I am struggeling with selenium.

Basically I want to click the following element to toggle the element:

<div class="view-icon fadeIn" title="" data-placement="top" data-toggle="tooltip" data-original-title="Switch to List View">
<i class="fa fa-bars"></i>
</div>

It changes to:

<div class="view-icon fadeIn" title="" data-placement="top" data-toggle="tooltip" data-original-title="Switch to Tab View">
<i class="fa fa-list-alt"></i>
</div>

After that I just want to fill in the form and test its output.

The method I wrote for clicking this element:

public void clickAtListView() {
        WebElement listView = driver.findElement(By.xpath("//div[@class='view-icon fadeIn']"));
        listView.click();
    }

However, i am getting:

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 50 milliseconds

Any recommendations why I get this exception?

I appreciate your answer!

UPDATE

It seems to me that the list element gets shown when I put Thread.sleep(10000); before:

However, i still get the exception ;(

2 Answers 2

2

As your sent exception said the element is not visible to take any action.

Hence, your code

WebElement listView = driver.findElement(By.xpath("//div[@class='view-icon fadeIn']"));

gets a hidden element (E.g. "View Tab" element). Please try this one

WebElement listView = driver.findElement(By.xpath("//div[@data-original-title='Switch to List View']"));
Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you just need to add one extra path to your XPath:

driver.findElement(By.xpath("//div/[@class='view-icon fadeIn']/i"));

Additionally, instead of defining separate elements for Tab View and List View, you can use the selector above as, for example, Toggle Views.

Comments

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.