Reputation: 808
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:
In debug mode.
After clicking Continue
in VS when exception appears.
When i am moving mouse manually on the screen.
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
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
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