selenium the xpath expression cannot be evaluated

naveen chettigari's picture

I am facing this exception in IE browser,these xpath works fine in other browser with all windows combination.

Here are the xpath's below provided.

1. //form[@id='form1']/div[2]/table/tbody/tr[2]/th

2. //tr[2]/th

Please provide a solution for this issue which am unable to replicate.

Error:

org.openqa.selenium.InvalidSelectorException: The xpath expression '//form[@id='form1']/div[2]/table/tbody/tr[2]/th' cannot be evaluated or does not result in a WebElement

1 Answer

Matthew Heusser's picture

I'm afraid I can't answer this without knowing the web page. I'm assuming you have used xpath/selenium on similar pages that worked just fine?

 

I've got a couple of ideas for you -

1) My guess is the page just isn't fully loaded when the xpath is executed. Trying injecting a wait - 30 seconds - before the selector. 

2) Get selenium IDE, try to write the same test. Don't use the generated code; just look at the xpath and compare it to what you have.

Good luck!

 

StickyMinds is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.