Reputation: 4245
I would like to use WebDriver (Firefox) to test my webpage, but I always get this message:
Unable to locate element: {"method":"xpath","selector":"//li[@id='something_spicy']"}
But, the really strange thing is that if I copy the element locator "//li[@id='something_spicy']"
and paste it into Firefinder then it works. Basically, I ran out of thoughts about what could be the root cause.
I use C# and here is the code:
movedElement = driver.FindElement(By.XPath("//li[@id='" + originalOrderOfSportContainers[1] + "']"));
Did I do something wrong? Have I missed something?
Upvotes: 0
Views: 646
Reputation: 1825
provide a snippet of the html code of your page.
There is a chance that element is not there immediately after the page is loaded,
but appears a bit later as a result of some javascript function execution.
If this is the case, use explicit wait to wait for element to appear before using it.
Upvotes: 1