Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

How to get id or xpath of a element based on the text present in it

View previous topic View next topic Go down

How to get id or xpath of a element based on the text present in it

Post by mgharikrishnan on Wed Jul 27, 2011 4:35 pm

Hi friends,

Please help me with this. I have a text say "Gary" in a web page, which is displaying in a table. I need to get the xpath or the id of the location, where word "Gary" is present in the web page. IS it possible to achieve it. If yes, please help me in doing it.

Thanks,
Hari

mgharikrishnan
Active particpant
Active particpant

Posts : 10
Join date : 2011-06-20

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by freesky on Thu Jul 28, 2011 10:05 am

use 'Xpath checker'

freesky
Amateur
Amateur

Posts : 72
Join date : 2011-04-13

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by mgharikrishnan on Thu Jul 28, 2011 2:16 pm

Thanks for the reply, freesky. But the thing is that, I want to do it while is execute the script. My problem is that, when I register a user, his username & email id will display in a table in the web page. In the script, i have to search for that username and take the xpath of that username....

~ Harri...

mgharikrishnan
Active particpant
Active particpant

Posts : 10
Join date : 2011-06-20

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by freesky on Thu Jul 28, 2011 3:04 pm

you want to get the xpath automation according to the text present.
I haven't heard that we can do that yet.

freesky
Amateur
Amateur

Posts : 72
Join date : 2011-04-13

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by Arthur on Mon Aug 01, 2011 1:27 pm

Hi,

You can do this using Selenium-RC Just get the xpath of first Element in the table. Now get the same for the second element in the table verify the the change the change should be the row number of table.
With above steps only search the row changing.

This row number can be placed as variable and get the text of each table row in the specific column where it should be seen. When while traversing the element is found then break the loop and the the xpath can be retrieved dynamically.

You cant do this in Selenium IDE this the situation where you have to use the selenium RC.

Thanks.

Arthur
Active particpant
Active particpant

Posts : 23
Join date : 2011-05-23
Location : Pune

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by mgharikrishnan on Mon Aug 01, 2011 9:17 pm

Hi Arthur,

Thanks for your comment. I was able to achieve this task today. I am putting the code here, so that it will be helpful for someone like me.

Code:

//This gets the number of data displaying in the table
int rowCount = (Integer)selenium.getXpathCount("//table[@id='pending-reg']/tbody/tr");
//Looping thru the data
for(int i=3; i<=rowCount; i++)
{
String username = selenium.getText("//table[@id='pending-reg']/tbody/tr["+i+"]/td[1]");
Thread.sleep(500);
System.out.println("Username = "+username);
//Looking for the username Gary
if(finame.equalsIgnoreCase("gary"))
{
//Getting the password of Gary
String password = selenium.getText("//table[@id='pending-reg']/tbody/tr["+i+"]/td[2]");
Thread.sleep(500);
System.out.println("Password = "+password);
}
}

mgharikrishnan
Active particpant
Active particpant

Posts : 10
Join date : 2011-06-20

Back to top Go down

Re: How to get id or xpath of a element based on the text present in it

Post by Sponsored content Today at 7:28 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum