Selenium getAttribute(value) and getAttribute(maxlength) script examples



package selenium_examples;


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


public class Test {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();
driver.get("http://book.spicejet.com/");
System.out.println(driver.findElement(By.name("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1_CTXT")).getAttribute("value"));




}
}

Output:-

Leaving from...


getAttribute() method :- Gets the value of a given attribute of the element.

getAttribute("value") retrieves the value inside the fields.In above script from http://book.spicejet.com,it retrieves text from "Leaving from" Dropdown box .


Script 2

package selenium_examples;


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


public class Test {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();
driver.get("http://ebay.in");
System.out.println(driver.findElement(By.id("gh-ac")).getAttribute("maxlength"));




}
}

Output:-

300

getAttribute("maxlength") retrieves the maxlength of the field.In above script from http://ebay.in ,it retrieves maxlength of search textbox .



No comments:

Related Posts Plugin for WordPress, Blogger...