Tuesday, 8 March 2011

Using xpather for xpaths

Aim:
Use Firefox's xpather to locate the xpath and then update the original script.

Difficulty Level: Hard


What you will learn?
  • xpaths
  • xpather for firefox
Pre-requisites:
Exercise Steps:
  1. Open up Firefox
  2. install xpather by following "How to install xpather in Firefox?"
  3. copy the original script below into Selenium IDE
  4. run the original script
  5. notice in particular the 'assertTextPresent' command and then use xpather tool to replace with an xpath.
  6. now rerun the script with the xpath

Conclusions

Related Entries



Solution:

Zip file location: ( download from here)
C:\FoundationSelenium\Ex10\BeforeXpather.html, C:\FoundationSelenium\Ex10\AfterXpather.html



Here is the script in HTML texts before using xpather (original script):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://foundation.time2test.co.uk/" />
<title>BeforeXpather</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">BeforeXpather</td></tr>
</thead><tbody>
<tr>
 <td>open</td>
 <td>/</td>
 <td></td>
</tr>
<tr>
 <td>clickAndWait</td>
 <td>link=Log in</td>
 <td></td>
</tr>
<tr>
 <td>assertTextPresent</td>
 <td>Username</td>
 <td></td>
</tr>
<tr>
 <td>assertTextPresent</td>
 <td>Password</td>
 <td></td>
</tr>
<tr>
 <td>type</td>
 <td>id=user_login</td>
 <td>admin</td>
</tr>
<tr>
 <td>type</td>
 <td>id=user_pass</td>
 <td>time4test</td>
</tr>
<tr>
 <td>clickAndWait</td>
 <td>id=wp-submit</td>
 <td></td>
</tr>
<tr>
 <td>waitForElementPresent</td>
 <td>//div[@id='user_info']/p/a[2]</td>
 <td></td>
</tr>
</tbody></table>
</body>
</html>



Here is the script in HTML texts after using xpather ( modified with xpather)



BeforeXpather


BeforeXpather
open /
clickAndWait link=Log in
assertTextPresent Username
assertTextPresent Password
type //input[@id='user_login'] admin
type //input[@id='user_pass'] time4test
clickAndWait id=wp-submit
waitForElementPresent //div[@id='user_info']/p/a[2]
clickAndWait //li[@id='menu-posts']/a
clickAndWait //li[@id='menu-posts']/div[3]/ul/li[2]/a
click id=title-prompt-text
type id=title New Post
clickAndWait id=publish
clickAndWait link=Log Out


Helpful Video


10 comments:

  1. notes
    1. the video needs to show the script before using xpather
    2. video needs to show xpather install
    3. video needs to show how to use xpather to get the xpath
    4. video needs to show the new script using xpaths

    ReplyDelete
  2. I have updated video file as per your comments, please review.

    ReplyDelete
  3. the html text in the blog is not correctly formatted.

    ReplyDelete
  4. also, post the original script before entering the xpaths into the blog

    ReplyDelete
  5. DONE, I have added original script as well and previous one also in correct format.

    ReplyDelete
  6. One of the scripts needs to be placed in the html highlighter syntaxer.

    ReplyDelete
  7. todo: can you go through the video and create bullet points of the main steps that the video is showing and place the content at the beginning of the blog.

    ReplyDelete
  8. notes for viresh
    add links to install xpather
    ensure that the video shows xpather in use
    add steps on what the exercise is showing.

    ReplyDelete
  9. Also, need to establish the aim of the exercise.

    ReplyDelete
  10. Hi Viresh, what changes you want here, please explain little bit in detail so that I can make changes accordingly.

    ReplyDelete

Thank you for your comment
- Time2test Team