Table of content

getTitle

We can get title of page using getTitle(), it returns title as string

page title : chercher.tech


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class GetTitle 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://chercher.tech");
								System.out.println("Page title is : "+driver.getTitle());							
							}
						}

					

Output: Page title is Selenium Webdriver

Open Google.com and verify whether the title is Google or not ?

						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class Refresh 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://google.com");
								if (driver.getTitle().equals("Google")) 
								{
									System.out.println("Title is Google ");
								}
								else 
								{
									System.out.println("Title is not Google");
								}							
							}
						}
					

Like wise you can also compare whether title has Google as a part of title or not

Take Element Screenshot

Get URL

We can get url of page the using getCurrentUrl(), it returns Url as string

page url


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class GetUrl 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();
								driver.get("https://chercher.tech");
								// below line gets the url of a website
								driver.getCurrentUrl();									
							}
						}
					

More than Two Browser Windows

Get Page Source

We can get page source of page the using getPageSource(), it returns page source of the as string.


						import org.openqa.selenium.WebDriver;
						import org.openqa.selenium.firefox.FirefoxDriver;

						public class PageSource 
						{
							public static void main(String[] args) throws Exception 
							{
								WebDriver driver=new FirefoxDriver();	
								driver.get("https://chercher.tech");			
								driver.getPageSource();							
							}
						}

					

Handle dropdowns in selenium

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Protractor Training

new tutorial I am starting new Protractor training batch on Weekends. It is two days course from 01-june-2019 to 02-june-2019 based on class room (BANGALORE)

Interested people can confirm the seat by calling to +91 8971673487 or whatsapp to +91 9003381224

Find the course content : View Content