Thursday, July 1, 2010

Selenium IDE: Use XPath if no id found in elemnet you want to work with

If you are working with IDE and recording your script. There may be some cases where you IDE can not record the action to the element that do not have any id. In such case you need to find the id manually and provide it to the script to cover your action. XPath help you here to navigate your site.

In one of my project when I was recording my script for create a post, I found that IDE is unable to record the text box activity. Actually that text box was Javascript content editor 'Tinymce' . Later I recognized that IDE is unable to find this editor as there was no label used for this. So I used X paths to locate the element ID. It looks like..
id('commentBodyField')

The XPath can be found using the Firefox plug-in. https://addons.mozilla.org/firefox/addon/1095
to find the XPath just right click over the desired element and click on view Xpath.

3 comments :

  1. Thanks Vishal for this useful information. Could you please tell me more on XPath, or simply tell me good link were I can find detail on this.

    ReplyDelete
  2. Hi Vishal...
    I have a question, may be irrelevant to the current topic... hope u could help...
    I am tryin to run my tests in Internet Explorer, using Selenium RC.
    I running the htmlSuite from the Command prompt and it works very fine with the firefox and chrome commands but it was unsuccessful with the *iehta, *iexplore and *iexploreproxy commands...
    when I use the *iehta and *iexplore commands, it throws an error: html exception seen
    Where as when I tried *iexploreproxy, it opened up the test runner in explorer window and i could see my testsuite in the left side of the window but none of my test cases are loaded in the current.
    And I could see an error on the page saying
    "Problems with the web page might prevent it from being displayed
    properly or functioning properly"
    Error: Access is denied

    Kindly suggest....
    Would really appreciate!!!

    Thanks
    Sats

    ReplyDelete
  3. Hi Sats,

    I gone through your problem and tried to understand why this is coming. In fact from last one year i have not been using this tool.
    One thing I can suggest which may help you to find the solution of your problem . You may or may not be aware of a good forum on selenium users. u can try there if u get ur query addressed there.
    http://old.nabble.com/Selenium-IDE-f14085.html

    thanks
    Vishal Sachan

    ReplyDelete