0

I have a web page with the following table

Assessment name |       Task             |    Status

 Test A         | Practice               |  Not started

                | Assessment             |  Not started

Test B          | Practice               | Not started

                | Assessment             | Not started

Also find the html code for it.

<table class="gridRow" cellspacing="0" summary="For each assessment" style="border-collapse:collapse;">
    <tr>
        <th class="gridHeaderHide" scope="col">&nbsp;</th><th class="gridHeader" scope="col">Assessment name</th><th class="gridHeader" scope="col">Task</th><th class="gridHeader" scope="col">Status</th><th class="gridHeader" scope="col" abbr="Overall time you will need">Overall time you will need</th><th class="gridHeader" scope="col" abbr="Time limit">Time limit</th><th class="gridHeader" scope="col"><a tabindex="502" href="javascript:__doPostBack('ctl00$ErrorMessageContentPlaceHolder$gdvAssessmentHome','Sort$Deadline')">Deadline</a></th><th class="gridHeaderWhatUNeed" scope="col" abbr="What you need">What you need </th>
    </tr><tr class="gridRow" align="center">
        <td class="gridcolHide" rowspan="2">
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgCompleted" title="Completed" src="../Images/completed.gif" alt="Completed" style="border-width:0px;" />
                                </div>
                            </td><td class="gridcol" rowspan="2">
                                <span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_lblCandidateFriendlyName">Test A</span>
                            </td><td class="gridcol">

                                <input type="submit" name="ctl00$ErrorMessageContentPlaceHolder$gdvAssessmentHome$ctl02$PracticeTask" value="Practice" id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_PracticeTask" tabindex="503" class="linkButton" />
                            </td><td class="gridcol">Not started</td><td class="gridcol">
                                15&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_lblMins1" class="label">Minutes</span>
                            </td><td class="centeredImage">
                                <div style='display:block'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_PractiseImage" src="../Images/AH_Transparent_Icon.gif" alt=" " style="border-width:0px;" />
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgClock" title="Timer on" src="../Images/timer_on.gif" alt="Timer on" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_lblMins" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgTimerPlusOn" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_Label2" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgTimerOff" title="Timer off" src="../Images/Timer_plus.gif" alt="Timer off" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_Label1" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgTimerPlusOff" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_Label3" class="label">Minutes</span>
                                </div>
                            </td><td class="gridcol" rowspan="2">21/03/2013</td><td class="gridcolWhatUNeed" rowspan="2">
                                <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl02_imgMouse" title="Mouse" src="../Images/Mouse.gif" alt="Mouse" style="border-width:0px;" />
                            </td>
    </tr><tr class="gridRow" align="center">
        <td class="gridcol">

                                <input type="submit" name="ctl00$ErrorMessageContentPlaceHolder$gdvAssessmentHome$ctl03$PracticeTask" value="Take assessment" id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_PracticeTask" tabindex="504" class="linkButton" />
                            </td><td class="gridcol">Not started</td><td class="gridcol">
                                30&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_lblMins1" class="label">Minutes</span>
                            </td><td class="centeredImage">
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_PractiseImage" src="../Images/AH_Transparent_Icon.gif" alt=" " style="border-width:0px;" />
                                </div>
                                <div style='display:block'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_imgClock" title="Timer on" src="../Images/timer_on.gif" alt="Timer on" style="border-width:0px;" />
                                    19&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_lblMins" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_imgTimerPlusOn" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    19&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_Label2" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_imgTimerOff" title="Timer off" src="../Images/Timer_plus.gif" alt="Timer off" style="border-width:0px;" />
                                    19&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_Label1" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_imgTimerPlusOff" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    19&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl03_Label3" class="label">Minutes</span>
                                </div>
                            </td>
    </tr><tr class="gridRow" align="center">
        <td class="gridcolHide" rowspan="2">
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgCompleted" title="Completed" src="../Images/completed.gif" alt="Completed" style="border-width:0px;" />
                                </div>
                            </td><td class="gridcol" rowspan="2">
                                <span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_lblCandidateFriendlyName">Test B</span>
                            </td><td class="gridcol">

                                <input type="submit" name="ctl00$ErrorMessageContentPlaceHolder$gdvAssessmentHome$ctl04$PracticeTask" value="Practice" id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_PracticeTask" tabindex="505" class="linkButton" />
                            </td><td class="gridcol">Not started</td><td class="gridcol">
                                15&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_lblMins1" class="label">Minutes</span>
                            </td><td class="centeredImage">
                                <div style='display:block'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_PractiseImage" src="../Images/AH_Transparent_Icon.gif" alt=" " style="border-width:0px;" />
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgClock" title="Timer on" src="../Images/timer_on.gif" alt="Timer on" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_lblMins" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgTimerPlusOn" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_Label2" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgTimerOff" title="Timer off" src="../Images/Timer_plus.gif" alt="Timer off" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_Label1" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgTimerPlusOff" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    &nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_Label3" class="label">Minutes</span>
                                </div>
                            </td><td class="gridcol" rowspan="2">21/03/2013</td><td class="gridcolWhatUNeed" rowspan="2">
                                <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgMouse" title="Mouse" src="../Images/Mouse.gif" alt="Mouse" style="border-width:0px;" /><img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgCalculator" title="Calculator" src="../Images/Calculator.gif" alt="Calculator" style="border-width:0px;" /><img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_imgPaper" title="Pen and paper" src="../Images/pen_and_paper.gif" alt="Pen and paper" style="border-width:0px;" />
                            </td>
    </tr><tr class="gridRow" align="center">
        <td class="gridcol">

                                <input type="submit" name="ctl00$ErrorMessageContentPlaceHolder$gdvAssessmentHome$ctl05$PracticeTask" value="Take assessment" id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_PracticeTask" tabindex="506" class="linkButton" />
                            </td><td class="gridcol">Not started</td><td class="gridcol">
                                30&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_lblMins1" class="label">Minutes</span>
                            </td><td class="centeredImage">
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_PractiseImage" src="../Images/AH_Transparent_Icon.gif" alt=" " style="border-width:0px;" />
                                </div>
                                <div style='display:block'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_imgClock" title="Timer on" src="../Images/timer_on.gif" alt="Timer on" style="border-width:0px;" />
                                    25&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_lblMins" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_imgTimerPlusOn" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    25&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_Label2" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_imgTimerOff" title="Timer off" src="../Images/Timer_plus.gif" alt="Timer off" style="border-width:0px;" />
                                    25&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_Label1" class="label">Minutes</span>
                                </div>
                                <div style='display:none'>
                                    <img id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_imgTimerPlusOff" title="Extra time allowed" src="../Images/Timer_plus.gif" alt="Extra time allowed" style="border-width:0px;" />
                                    25&nbsp;&nbsp;<span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl05_Label3" class="label">Minutes</span>
                                </div>
                            </td>
    </tr><tr class="gridRow" align="center">

Now I have to clcik Test B - Practice link I used the following xpath to click it as the links are dynamically loaded

xpath=//*[contains(text(),'Test B')]/../../td[3]/input

This works for a particular language but when I change the display language (say Chinese) for the web page it does not work.

Please help how can click the link. Note: The web page might contain Test B row alone or both test A and Test B. (Dynamically loaded) I have to select the practice link based on the test

Please let me know if more info is required

user1984004PRI
  • 313
  • 2
  • 8
  • 21
  • 1
    You really need to include the actual HTML of the table, not a drawing of it. – Ross Patterson Mar 20 '13 at 10:57
  • In chinese language what is the display text for Test B ? If you change language, Is there any change in html DOM ? How many languages you've like that ? – Santoshsarma Mar 20 '13 at 13:42
  • It will be mere translation of Test B in Chinese language.Similarly I have 31 languages to test. Basic html DOM remains the same, but the problem is test B can be alone or it can be with test A. So the link id changes accordingly (dynamically) – user1984004PRI Mar 20 '13 at 14:43
  • Is the text the only thing changing? I would assume so in which case the fact you're using 'contains(text(),'Test B')' and it's going to break for every language. You need a Xpath that doesn't rely on the text. – so cal cheesehead Mar 20 '13 at 15:20
  • Yes , I need to use xpath without using contains(text(),'Test B') but I didn't know how to locate the element . I need to click practice link based on assessment name (Test B) . Also,the location of test B keeps changing (dynamic) – user1984004PRI Mar 21 '13 at 09:14

2 Answers2

0

I think here the problem is that when you change the display language from English to another language the value "Test B" also changes. You are specifying in your XPath identifier //*[contains(text(),'Test B')] to look explicitly for "Test B", Selenium fails to find this value when the language is changed.

Looking at your HTML code, I felt that you have unique ID attributes for all the tags, which I think will not change on changing the language.

try using "Id" attribute in your XPath instead of text, for instance,

XPath("//td[@id='ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_lblCandidateFriendlyName']")

</td><td class="gridcol" rowspan="2">
    <span id="ctl00_ErrorMessageContentPlaceHolder_gdvAssessmentHome_ctl04_lblCandidateFriendlyName">Test B</span>
</td><td class="gridcol">

As you have to run your test for different language options, you need some uniqueness in web object identification. I think using Id will guarantee uniqueness in object identification at least on per test case basis for all the language options.

Another approach you can follow is slightly complicated, based on the language selected convert value of "Test B" also to same language and use it as a variable value in XPath string.

Step will be , 1. Convert unique identification "Test B" to unicode. 2. Convert unicode value to browser language you have selected. 3. Use in XPath the above value as a variable string, changing programmatic.

Last approach is you can store your web element Table values to an IList and write test script using index value in IList for object reference. Here also you will have to write different scripts for different test cases, considering the dynamic object creation. Even though you change the browser language, if you are using the index value from IList for scripting, it will be standard.

CheryJose
  • 280
  • 1
  • 6
0

Isn't it obvious? You are using the text to identify the element, it will not work if the language changed. The text varies with the language.

How about doing something like this?

If testing in English String text = "Test B"

Else if testing in Chinese String text = "测试B";

 xpath="//*[contains(text(), "+text+" )]/../../td[3]/input"

Instead of this approach why wouldn't you avoid using the text to identify the element so that you are no longer depending on the text which you need to pass each time you change the language. Or Figure out a logic which handles this dynamic content, you need to follow the same procedure which you do while testing this test case manually.

Code Enthusiastic
  • 2,827
  • 5
  • 25
  • 39
  • I had to click the practice link based on the assessment name , which i can achieve through contains(text()) command only. Also the editor will not support other languages to be enter , it will be pasted as symbols – user1984004PRI Mar 25 '13 at 17:05
  • Can you tell me how would you do it if you are doing it manually? – Code Enthusiastic Mar 25 '13 at 17:08