- mgharikrishnanActive particpant
- Posts : 10
Join date : 2011-06-20
How to get id or xpath of a element based on the text present in it
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
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
- freeskyAmateur
- Posts : 72
Join date : 2011-04-13
Re: How to get id or xpath of a element based on the text present in it
Thu Jul 28, 2011 10:05 am
use 'Xpath checker'
- mgharikrishnanActive particpant
- Posts : 10
Join date : 2011-06-20
Re: How to get id or xpath of a element based on the text present in it
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...
~ Harri...
- freeskyAmateur
- Posts : 72
Join date : 2011-04-13
Re: How to get id or xpath of a element based on the text present in it
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.
I haven't heard that we can do that yet.
- ArthurActive particpant
- Posts : 23
Join date : 2011-05-23
Location : Pune
Re: How to get id or xpath of a element based on the text present in it
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.
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.
- mgharikrishnanActive particpant
- Posts : 10
Join date : 2011-06-20
Re: How to get id or xpath of a element based on the text present in it
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);
}
}
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);
}
}
Permissions in this forum:
You cannot reply to topics in this forum