David Cunningham
David Cunningham

Reputation: 997

Cannot click on Angular-JS button with selenium web-driver: ElementNotVisibleException

I trying to click on this button (it is clearly on the page and in view):

<button class="ui tertiary button" data-ng-click="addRoom()" data-ng-disabled="pendingRequests >= 1">ADD ROOM TO CRUISE CART</button>

Here is my code:

driver.FindElement(By.CssSelector("button[data-ng-click^='addRoom']")).Click();

It always throws this error:

OpenQA.Selenium.ElementNotVisibleException : Element is not currently visible and so may not be interacted with

Is Selenium WebDriver compatible with angular JS?

Upvotes: 2

Views: 3517

Answers (3)

Rijo Mon
Rijo Mon

Reputation: 169

Change your code to the following:

driver.findElement(By.xpath("//button[contains(text(),'ADD ROOM TO CRUISE CART')]")).click();

Upvotes: 0

Jay Byford-Rew
Jay Byford-Rew

Reputation: 6024

Had the same issue, you can do this (using linq)

driver.FindElement(By.CssSelector("button[data-ng-click^='addRoom']")).First(x=>x.Displayed()).Click();

Upvotes: 0

David Cunningham
David Cunningham

Reputation: 997

I have managed to identify the problem, There are multiple buttons with the exact same XPath one is visible at given time the other are not visible. I

   var list = driver.FindElements(By.CssSelector("a[data-ng-click='addRoom()']")).ToList();

        foreach (var item in list)
        {
            Console.WriteLine(item.Displayed);

            if(item.Displayed)
            {
                item.Click();
            }
        }

This got the active button, Thank you for all your help. I can move forward now

Upvotes: 1

Related Questions