Get methods in Selenium Webdriver.

Test Automation 0 Comment 52

Webdriver class Get methods

1.get();

The method  is used to get or launch the specific site or website.

Syntax: get(url)
Example: driver.get();

2.getText();

The method  is used to get  text of a located element in the current page..

Syntax: getText()
Example:

string x=driver.findElement(By.name(“………….”)).getText();

3.getAttribute();

The method  is used to get attribute value for a located element in the current page.

Syntax: getAttribute()
Example:

string y=driver.findElement(By.name(“………….”)).getAttribute();

4.getcssValue();

The method  is used to get style attribute value for a located element in the current page.

Syntax: getcssValue();

Example:

string s=driver.findElement(By.name(“………….”)).getcssValue();

5.getTitle():The method  is used to get title of currently active page.

Syntax: getTitle()
Example:

string a =driver.getTitle();

6.getCurrenturl();

The method  is used to know weather the current site is securable or not.

Syntax: getCurrenturl();
Example:

string u =driver.getCurrenturl();

7.getPagesource();

The method  is used to get the HTML source of current page.

Syntax: getPagesource();
Example:

string p =driver.getPagesource();

8.getwindowHandles();

The method  is used to get the all handle numbers of browser window into an array.

Syntax: getwindowHandles();
Example:

Arraylist<string> q =new Arraylist<string>(driver.getwindowHandles(1));

9.getfirstSelectedOption();The method  is used to get the first selected option in a drop down.

Example:

Select s= new select(driver.findElement(By.name(“………….”))

webElement x= s.getfirstSelectedOption();

y=x.getText();

system.out.println(y);

10.getAllSelectedOptions();

The method  is used to get the first selected option in a drop down.

Example:

Select s= new select(driver.findElement(By.name(“………….”))

list<webElement> x= s.getAllSelectedOptions();

y=x.size();

system.out.println(y);

for(int i=0;i<=y;i++)

{

L=s.get(i).getText();

system.out.println(L);

}

11.getOptions();

The method  is used to get the all options in a drop down.

Example:

Select s= new select(driver.findElement(By.name(“………….”))

list<webElement> x= s.getOptions();

y=x.size();

system.out.println(y);

for(int i=0;i<=y;i++)

{

L=s.get(i).getText();

system.out.println(L);

}

Above getOptions(),getfirstSelectedOption(),getAllSelectedOptions() are used  to handle the dropdowns.

Author

Related Articles

Leave a comment

You must be logged in to post a comment.

© 2016 4frienz. Powered By Flowers

Back to Top