[Urgent]How to handle Dynamic Element with ID

105 views
Skip to first unread message

kvvnk ravikumar

unread,
Apr 28, 2015, 5:19:08 AM4/28/15
to seleniu...@googlegroups.com
Hi All,

I'm working on web application, there is a button with ID like below:


pt1:USma:0:MAt3:1:pt1:Manag1:1:r:JobDe1:0:dialogForPositionChange::yes 

but the initial part pt1:USma:0 is constant and last part dialogForPositionChange::yes  is constant 

so I tried to use xpath with the method ends-with like below:

//div[ends-with(@id,'dialogForPositionChange::yes')]  But its not returning any value when I check this text in Xpath checker.

Could any one help in this regard..Its bit urgent..

 

Brijesh Yadav

unread,
Apr 28, 2015, 6:08:57 AM4/28/15
to seleniu...@googlegroups.com
Hi

try with below id, I hope it should work.

//input[contains(@id,"_txtSearch")]

//input[contains(@id,"dialogForPositionChange")]


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/562bb363-2dba-48c5-8891-5c2c69f722a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kvvnk ravikumar

unread,
Apr 28, 2015, 6:32:04 AM4/28/15
to seleniu...@googlegroups.com
Many Thanks Brijesh for your reply.

If I use //input[contains(@id,"dialogForPositionChange")] there are two buttons getting identified, If we can write a pattern matching like  starting with "pt1:USma:0:MAt' and ends with  "dialogForPositionChange" then it should identifies uniquely. 

But when I try to use ends-with its not giving any result.

How to write a regular expression to meet this requirement.

Brijesh Yadav

unread,
Apr 28, 2015, 7:26:54 AM4/28/15
to seleniu...@googlegroups.com

I am not sure about achieving it using regular expression but as you said it has some constant part in id. You can use that constant part.

Like below one.

//input[contains(@id,"dialogForPositionChange::yes")]

Recognize the constant part of object and write it over there.

Identify the unique part (text) of id between two buttons and give it over there.


-----------------------------------Alternate -------------------------------

you can use absolute / relative dom xpath rather than using pattern or other thing in xpath.

for example - html/body/form/button

use firepath to identify the xpath



Abhishek Singh

unread,
Apr 28, 2015, 11:08:11 AM4/28/15
to seleniu...@googlegroups.com

Hi Ravikumar,

Since two web elements are getting identified because of this Xpath //input[contains(@id,"dialogForPositionChange")]  which you have tried.


Kindly try to use this pattern matching Xpath which checks two conditions

1. Starting with "pt1:USma:0:MAt

2. & Containing  "dialogForPositionChange"

 

Kindly try below Xpath and let me know if this resolves your problem

//input[starts-with(@id,'pt1:USma:0')][contains(@id,'dialogForPositionChange::yes')]

 

Regards,

Abhishek

Brian Smith

unread,
Apr 28, 2015, 5:28:11 PM4/28/15
to seleniu...@googlegroups.com
You can use "//input[contains(@id,'pt1:USma:0') and contains(@id,'dialogForPositionChange::yes')]" as a comparison path checking for the availability of both strings. Using this method the order of the two contains() statements is not important.

tulsi.tester

unread,
Apr 29, 2015, 1:19:26 AM4/29/15
to seleniu...@googlegroups.com
Hi Ravi Kumar,

As most of the browser's support only Xpath 1.0 version instead of Xpath 2.0, your ends-with function doesn't works. Hence you can tweak this using the following code

I am assuming the following html code for a simple input field

<input name='firstname'>

and i am trying to find whether the name attribute ends with name or not



//input['name'=substring(@name,5,8)]

This is return the correspoding web element. You can try the same logic with your code.



On Tuesday, April 28, 2015 at 2:49:08 PM UTC+5:30, kvvnk ravikumar wrote:

kvvnk ravikumar

unread,
Apr 29, 2015, 2:05:27 AM4/29/15
to seleniu...@googlegroups.com
Many Many Thanks a lot, This Group rocks :-) After lot of research i ended up using below:
//input[contains(@id,'pt1:USma:0') and contains(@id,'dialogForPositionChange::yes')]"
And the same was suggested by Brian and Abhishek.. Special thanks for you :-) 

İsmail KOÇ

unread,
Apr 29, 2015, 2:13:24 AM4/29/15
to seleniu...@googlegroups.com

Hi,
Use contains tag in xpath. Not ends-with

28 Nis 2015 12:19 tarihinde "kvvnk ravikumar" <ravikum...@gmail.com> yazdı:

Gopa Kishore Mindi

unread,
Apr 29, 2015, 2:17:18 AM4/29/15
to seleniu...@googlegroups.com
Hi,

Please try with the below xpaths and let me know if it does not work for you.

//*[contains(@id,'pt1:USma:0:MAt3:')][contains(@id,'dialogForPositionChange::yes')]


//*[contains(@*,'pt1:USma:0:MAt3:')][contains(@*,'dialogForPositionChange::yes')]


Thanks,

Gopa

On Tuesday, April 28, 2015 at 2:49:08 PM UTC+5:30, kvvnk ravikumar wrote:

A R K Satyanarayana Raju

unread,
May 5, 2015, 9:44:47 AM5/5/15
to seleniu...@googlegroups.com
U can use 
(//input[contains(@id,"dialogForPositionChange")])[1] - for first element
(//input[contains(@id,"dialogForPositionChange")])[2] - for second element

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

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



--
A R K Satyanarayana Raju
Reply all
Reply to author
Forward
0 new messages