2

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?

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

Change your code to the following:

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

4 Comments

Sorry I should of mentioned the text is dynamic, so I can't use ADD ROOM TO CRUISE CART as a reference
driver.FindElement(By.LinkText("ADD ROOM TO CRUISE CART")).Click(); will work but the text ADD ROOM TO CRUISE CART will change so I can't use it
down vote Use this instead of your code driver.findElement(By.xpath("//button[@data-ng-click='addRoom()']")).click();
Use this code driver.findElement(By.xpath("//button[@data-ng-click='addRoom()']")).click();

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.