Quantcast

how to verify text present in a page

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to verify text present in a page

pradeep
Hi,

Using Selenium WebDriver, i'm trying to automate http://newtours.demoaut.com portal.

In this portal, once we register, the below confirmation message is displayed:

 Dear ,

Thank you for registering. You may now sign-in using the user name and password you've just entered.

Note: Your user name is xxx.


How to verify the above text in the WebDriver code? i tried by taking xpath as below, but after that i'm not sure how to  validate it.


 WebElement text =driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p/font/b"));

Any help would be appreciated.


Thanks,

Pradeep

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/aa71e7d2-9fbc-452b-a86b-eba6bbdf29d5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to verify text present in a page

Dhiraj
Hello Pradeep,

Use the following code (If location of text on page not matters)::

driver.getPageSource().contains(" ");

Thanks,
Dhiraj | Skype: dhiraj.chaubey



On Saturday, 31 August 2013 17:54:53 UTC+5:30, pradeep wrote:
Hi,

Using Selenium WebDriver, i'm trying to automate http://newtours.demoaut.com portal.

In this portal, once we register, the below confirmation message is displayed:

 Dear ,

Thank you for registering. You may now sign-in using the user name and password you've just entered.

Note: Your user name is xxx.


How to verify the above text in the WebDriver code? i tried by taking xpath as below, but after that i'm not sure how to  validate it.


 WebElement text =driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p/font/b"));

Any help would be appreciated.


Thanks,

Pradeep

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7649eeb3-1ca6-4d96-8961-90fdcf5e46c9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to verify text present in a page

Oscar Rieken



On Mon, Sep 2, 2013 at 1:59 AM, Dhiraj <[hidden email]> wrote:
Hello Pradeep,

Use the following code (If location of text on page not matters)::


Don't do this. there is no reason to search the whole page for the text you want. It would be better to make sure its in the right place. 
driver.getPageSource().contains(" ");
 

Thanks,
Dhiraj | Skype: dhiraj.chaubey



On Saturday, 31 August 2013 17:54:53 UTC+5:30, pradeep wrote:
Hi,

Using Selenium WebDriver, i'm trying to automate http://newtours.demoaut.com portal.

In this portal, once we register, the below confirmation message is displayed:
 Dear ,
 
 
Thank you for registering. You may now sign-in using the user name and password you've just entered.

Note: Your user name is xxx.


How to verify the above text in the WebDriver code? i tried by taking xpath as below, but after that i'm not sure how to  validate it.



 WebElement text =driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p/font/b"));

doing something like this is very brittle its depending that the object you want is in this exact location. better to try and locate the exact item you want and then get its text. I would suggest looking at the the http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebElement.html 
to see how to get the text of an element. 
and reply with the html of the part of the page that contains your text 
 
Any help would be appreciated.


Thanks,

Pradeep

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7649eeb3-1ca6-4d96-8961-90fdcf5e46c9%40googlegroups.com.

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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CACuB3fbOxVy4eB92eap%3DLRL7VqUWGCH82rxaeL%3D4YEY%2Be%2BBV0A%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to verify text present in a page

Bhupesh Pant
In reply to this post by pradeep
use Assert.assertTrue(text.getText().contains("Thank you for registering. You may now sign-in using the user name and password you've just entered."));

On Saturday, August 31, 2013 5:54:53 PM UTC+5:30, pradeep wrote:
Hi,

Using Selenium WebDriver, i'm trying to automate http://newtours.demoaut.com portal.

In this portal, once we register, the below confirmation message is displayed:

 Dear ,

Thank you for registering. You may now sign-in using the user name and password you've just entered.

Note: Your user name is xxx.


How to verify the above text in the WebDriver code? i tried by taking xpath as below, but after that i'm not sure how to  validate it.


 WebElement text =driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/p/font/b"));

Any help would be appreciated.


Thanks,

Pradeep

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1da0a6ad-1cfb-45dd-ad5c-6ddac6d257ec%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to verify text present in a page

Ashish Juyal
Hi Bhupesh 
                   customize your xpath rather than giving absolute xpath try to give relative xpath and give .getText() and assert it .


Regards
Ashish Juyal

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAKw4aj%2BFs_1_sE%3DiGuVR9WnD4TuA3V3HxC%2BhmsyWCDOMyiqEdA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to verify text present in a page

Christian LeMoussel
Hi Bhupesh,

as indicated by Ashish, you must customize your xpath.

For ex.
string sText = webdriver.findElements(By.XPath("//*[text() = '" + sTextToCheck + "']")).getText();
System.out.println(text);

Regards


Le mercredi 4 septembre 2013 11:04:42 UTC+2, Ashish Juyal a écrit :
Hi Bhupesh 
                   customize your xpath rather than giving absolute xpath try to give relative xpath and give .getText() and assert it .


Regards
Ashish Juyal

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/03dc45ec-8178-4be8-ab94-62d29c80b248%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...