Selenium With dynamic ID

1,157 views
Skip to first unread message

reshmi aneesh

unread,
Aug 8, 2012, 2:11:31 AM8/8/12
to seleniu...@googlegroups.com
Hi Everyone,

 

I am generating junit test code from selenium IDE. When I am executing selenium code in eclipse , I'm getting the following error:

com.thoughtworks.selenium.SeleniumException: ERROR: Element //div/span/a not found    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.DefaultSelenium.click(DefaultSelenium.java:167)
    at com.example.tests.Heartcore_webamin_4.testHeartcore_webamin_4(Heartcore_webamin_4.java:30)
   

As 'a' tag is having dynamic ID,i generate //div/span/a using cirebug inspect elment and then copying the xpath.

After running the code am getting error as its not found...Please help me am stuck at this for last two days.

thanks in advance

Reshmi




reshmi aneesh

unread,
Aug 8, 2012, 2:23:11 AM8/8/12
to seleniu...@googlegroups.com

Here is my code:

selenium.open("/");
        assertEquals("Login", selenium.getTitle());
        selenium.type("name=username", "admin");
        selenium.type("name=password", "admin");
        selenium.click("name=Login");
        selenium.waitForPageToLoad("30000");
        selenium.click("xpath=(//a[contains(@href, '/webadmin/index.content.jsp?menu=content')])[2]");
        selenium.waitForPageToLoad("30000");
        selenium.click("//a[contains(@href, '/webadmin/content/index.jsp?contentpackage=+&contentclass=page&contentbundle=%20&contentgroup=%20&contenttype=%20&status=%20&version=%20&menu=content&')]");
        selenium.waitForPageToLoad("30000");
        assertEquals("Pages", selenium.getTitle());
        selenium.click("//div/span/a");
        selenium.waitForPageToLoad("30000");
        selenium.click("//input[@value='Save & Close']");
        selenium.waitForPopUp("_save", "60000");
        selenium.waitForPageToLoad("60000");
        selenium.click("xpath=(//a[contains(@href, '/webadmin/logout.jsp')])[2]");
        selenium.waitForPageToLoad("30000");

here for selenium.click("//a[contains(@href, 'admin.jsp?id=41&0.6071347242772881')]"); i change is with XPath as selenium.click("//div/span/a");

thanks in advance

Reshmi




Hari

unread,
Aug 8, 2012, 3:25:10 AM8/8/12
to seleniu...@googlegroups.com
try this code by replacing it

selenium.click("//a[contains(@href, 'admin.jsp?id=41&')]");


its not works mean - See this link


starts-with

if your dynamic element's ids have the format <button id="continue-12345" /> where 12345 is a dynamic number you could use the following

XPath: //button[starts-with(@id, 'continue-')]  



Regards,
hari

thanks in advance

Reshmi




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ek87M_Vh0NIJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

reshmi aneesh

unread,
Aug 8, 2012, 5:03:29 AM8/8/12
to seleniu...@googlegroups.com
Will someone help me to solve this issue please....


On Wednesday, August 8, 2012 11:41:31 AM UTC+5:30, reshmi aneesh wrote:

Krishnan Mahadevan

unread,
Aug 8, 2012, 5:04:49 AM8/8/12
to seleniu...@googlegroups.com
Reshmi,
I believe "Hari" responded with some alternatives. Did you even give it a try ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/VNV6yuceVAcJ.

reshmi aneesh

unread,
Aug 8, 2012, 5:06:32 AM8/8/12
to seleniu...@googlegroups.com
Yeah tried still getting error...

Krishnan Mahadevan

unread,
Aug 8, 2012, 5:15:06 AM8/8/12
to seleniu...@googlegroups.com
Can you share the html source of the page wherein you are seeing failures when you run :  selenium.click("//div/span/a");  


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/8Lmeno9wTP0J.

reshmi aneesh

unread,
Aug 8, 2012, 5:20:25 AM8/8/12
to seleniu...@googlegroups.com
<tr>
    <td>open</td>
    <td>/webadmin/content/index.jsp?contentpackage=+&amp;contentclass=page&amp;contentbundle=%20&amp;contentgroup=%20&amp;contenttype=%20&amp;status=%20&amp;version=%20&amp;menu=content&amp;</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>//a[contains(@href, 'admin.jsp?id=41&amp;0.6071347242772881')]</td>
    <td></td>
</tr>

<tr>
    <td>assertTitle</td>
    <td>Update&nbsp;Checkout - 2. Order Details</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//input[@value='Save &amp; Close']</td>
    <td></td>
</tr>


the code which i make bold is changed as //div/span/a using xpath.

Krishnan Mahadevan

unread,
Aug 8, 2012, 5:31:38 AM8/8/12
to seleniu...@googlegroups.com
Reshmi,
I guess I wasn't clear enough with what I asked.

Please share the html source of the actual web page which contains the element that you are having issues with interacting and NOT your IDE html 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/C6JJ6TpmygQJ.

reshmi aneesh

unread,
Aug 8, 2012, 5:42:31 AM8/8/12
to seleniu...@googlegroups.com
webpage html:

<td>
  <div class="ricoLG_col data_grid_header_col4" style="width: 179px;">
  <div class="ricoLG_cell ricoLG_evenRow WCMindex_highlight" id="data_grid_header_0_4">
  <span title="Checkout - 2. Order Details" class="title">
      <a class="title" href="admin.jsp?id=290&amp;0.5409739573043904">Checkout - 2. Order Details</a>
  </span>
</div>
<div class="ricoLG_cell ricoLG_oddRow" id="data_grid_header_1_4">
  <span title="Checkout - 2. Ordre information" class="title">
       <a class="title" href="admin.jsp?id=210&amp;0.4120937476464255">Checkout - 2. Ordre    information</a>     </span>
</div>
</div>
</td>

Krishnan Mahadevan

unread,
Aug 8, 2012, 5:46:13 AM8/8/12
to seleniu...@googlegroups.com
Have you tried 

selenium.click("//a[contains(text(),'Checkout - 2. Ordre    information')");

instead of //a[contains(@href, 'admin.jsp?id=41&amp;0.6071347242772881')]


P.S: The spelling of "Order" is incorrect in your webpage :)

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/_loxEcPm2iMJ.

reshmi aneesh

unread,
Aug 8, 2012, 5:51:11 AM8/8/12
to seleniu...@googlegroups.com
Yeah i tried it before...

anji prassana

unread,
Aug 8, 2012, 11:31:49 PM8/8/12
to seleniu...@googlegroups.com
Hope we must specify identifier type as xpath= prior to the xapth in click function.say,
selenium.click("xpath=//a[contains(text(),'Checkout - 2. Ordre    information')]");

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/gdb13wpZTbkJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks&Regards
Anjaneyulu P
"The way you see the things is the way to think and is the way you react upon!!"

reshmi aneesh

unread,
Aug 9, 2012, 1:28:52 AM8/9/12
to seleniu...@googlegroups.com
no still its not working...its showing xpath not found.

anji prassana

unread,
Aug 9, 2012, 3:17:41 AM8/9/12
to seleniu...@googlegroups.com
try this..
 
selenium.click("xpath=//a[contains(text(),'Checkout')]");

anji prassana

unread,
Aug 9, 2012, 3:19:53 AM8/9/12
to seleniu...@googlegroups.com
try this as well
  selenium.click("xpath=//a[contains(.,'Checkout')]");

Mark Collin

unread,
Aug 9, 2012, 7:27:51 AM8/9/12
to seleniu...@googlegroups.com

Have you checked to see if the website is W3C compliant html?

 

If it’s not there is a good chance that the XPath won’t be found due to a missing closing tag or something similar.

 

Try running the page through this:

 

http://validator.w3.org/

 

If it fails validation get the HTML fixed and then try to automate it again.

RajSekhar

unread,
Aug 9, 2012, 7:42:04 AM8/9/12
to seleniu...@googlegroups.com
did you try to use 

selenium.click("link= Checkout - 2. Ordre    information");

best regards,
Raj sekhar.
Reply all
Reply to author
Forward
0 new messages