Dago
Dago

Reputation: 808

selenium webdriver c# strange behaviour

I am using Selenium Web Driver and encountered following exception while trying to click a proper element in web browser: Unable to locate element. XPaths are 100% correct. The strange thing is it is working ok when:

I would be grateful for any help.

EDIT: Thread.Sleep doesnt help. I am trying to click decrease Year button in web calendar. It works first time, but freezes the second time. But the object is still there. So i dont understand how it can be not visible.

Upvotes: 0

Views: 83

Answers (2)

Guy
Guy

Reputation: 50809

The driver is trying to locate the element before it loaded. Try waiting for it before clicking.

wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(path))).Click();

Upvotes: 1

Thiago Custodio
Thiago Custodio

Reputation: 18387

There are a few things you can try:

1-try a selector by ID instead of the xpath. Maybe new elements are being rendered and making the xpath didn't find the element.

2-implement a retry pattern

3-use thread sleep to let the page being full rendered.

Upvotes: 0

Related Questions