Friday, December 29, 2017
WebDriver Find out the substring from existing text on web page
WebDriver Find out the substring from existing text on web page
How to find out substring from existing text on web page using Selenium WebDriver
Get_Substring_frm_StringText.java
Steps:
- � Define Firefox Browser and open the Firefox Browser
- � Open the URL (Website)
- � Assign the text on String Variable
- � Find out the substring from string and assign on String Variable
- � Verify Assigned Text is matched with existing text on webpage
Selenium Code:
package Selenium_WebDriver;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;
public classGet_Substring_frm_StringText {
public static void main(String arg[]) {
//Define the Webdriver for Browser i.e. Firefox
WebDriver driver = new FirefoxDriver();
//Open the URL (Website)
driver.get("http://docs.seleniumhq.org/");
//Assign the text on String Variable
String textonWebpage = "Selenium is a suite of tools";
//Find out the substring from string and assign on String Variable
String SubString_textonWebpage = textonWebpage.substring(9, 19);
// Verify Assigned Text is matched with existing text on webpage (Text taken from Page HTML view source using right click on webpage)
if(driver.getPageSource().contains(textonWebpage)) {
System.out.println("Webpage contains Text = " + textonWebpage);
System.out.println("Webpage contains Substring Text = " + SubString_textonWebpage);
}
else {
System.out.println("Webpage NOT contains Text = " + textonWebpage);
System.out.println("Webpage NOT contains Substring Text = " + SubString_textonWebpage);
}
}
}
alternative link download
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.