[Selenium] Get elements method

Continue Selenium common functions part1

  1. fill in a text box


/**
* Descriptions: This method use to fill in form
* @param driver
* @param how
* @param locator
* @param strInput
*/

public void fillIn(WebDriver driver,String how,String locator,String strInput){
System.out.println("fill in object "+ how+" equal "+locator+" with text: "+strInput);
By el = getElement(how,locator);
driver.findElement(el).clear();
driver.findElement(el).sendKeys(strInput);
}

 

2.  Select item dropdown list


/**
* Descriptions: This method use to select element in drop down list
* @param driver
* @param how
* @param locator
* @param option
*/

public void select(WebDriver driver,String how,String locator,String option){
By el = getElement(how,locator);
Select listBox = new Select(driver.findElement(el));
listBox.selectByVisibleText(option);
}

 

3. click on element


/**
* Description: This method use to click on an web element
* @param driver
* @param how
* @param localtor
*/

public void click(WebDriver driver, String how,String locator){
System.out.println("Click on object with "+ how+" equal "+locator);
By el = getElement(how,locator);
driver.findElement(el).click();
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s