Sometime in Selenium (Webdriver or RC), we face problem in identifying the web table cell data. To identify the cell data we can use xpath, ids etc . Suppose we want to click on the first cell value, for this we need to extract the xpath with the help of firebug in firefox ( say, the extracted xpath of the first cell is “//*[@id=’1′]/td “ ). Now when we run our script ,it will show unable to find the xpath and we will be stuck (basically this problem comes when we are new to selenium,I faced this problem recently, but when one of my colleague also faced the same problem, I thought to share it with you all J).
Let see why its not able to find the above xpath, if we analyze this xpath ,table id is missing and @id=’1’ is the id of the row, and there is the possibility of other rows in different table have the same row id .So when selenium tries to identify the cell data, its get confused with row id .
Now, what can be the solution .First of all we need to find the table id .
Here suppose we want to operate(click,verify,retrieve) on “Mishra, Vivek”, which row id=1 and td=1 (See the xpath .//*[@id=’1’]td ),now lets modify it by seeing the firebug window ,where we have table id=jqPatientInfo .So our modified xpath is “//*[@id='jqPatientInfo']/tbody/tr/td”, wow this is working fine J
Instead of /tbody/tr/td, hierarchy, we can also give directly row id .In this case our xpath will be “//*[@id='jqPatientInfo']//*[@id='1']/td”