Hi Guys in this article we are going to discuss about how to get the following things
- URL
- Page Title
- Particular Text from Site
from webSite using Selenium Web driver.
This can be easily achieved using selenium inbuild Methods :
- getTitle();
- getText();
- getCurrentUrl();
In this Program :
- Navigating to http://www.automationplace.blogspot.com.
- Getting page Title using
String title = driver.getTitle();
System.out.println("Current
Title for the Page is : " + title);
3.Getting page Text using
WebElement pagetext=driver.findElement(By.xpath("//[@id='headerinner']/div[2]/p/span"));
String text=pagetext.getText();
System.out.println("Text
From Page "+text);
4 .Clicking on about link and Getting Current Page URL using
driver.findElement(By.xpath("//*[@id='Profile1']/div/dl/dt/a")).click();
Thread.sleep(7000);
String currentpageurl = driver.getCurrentUrl();
System.out.println("Current
Page URL is :"+currentpageurl);
Source Code :
package gettext;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
public class textinfo {
public static void main(String[] args) throws InterruptedException
{
// TODO Auto-generated
method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.navigate().to("http://www.automationplace.blogspot.com");
String title = driver.getTitle();
System.out.println("Current Title
for the Page is : " + title);
Thread.sleep(5000);
WebElement pagetext=driver.findElement(By.xpath("//*[@id='header-inner']/div[2]/p/span"));
String text=pagetext.getText();
System.out.println("Text From
Page "+text);
driver.findElement(By.xpath("//*[@id='Profile1']/div/dl/dt/a")).click();
Thread.sleep(7000);
String currentpageurl = driver.getCurrentUrl();
System.out.println("Current Page
URL is :"+currentpageurl);
}
}
Run the above program.your output looks like below.
Hope you like this post.
Thank you.
No comments:
Post a Comment