How to create a 'Select' function in keywords.java file? | Selenium Forum
M
Posted on 15/12/2015
How can i create a 'Select' function in the keywords.java file in order to select an option from the drop down? Like we have created functions navigate, click, input, etc..

M
Replied on 15/12/2015

you can use sendKeys to select a option.


M
Replied on 22/12/2015

I tried a simple program to select a language from the drop down in gmail.com page, but it didn't work (it doesn't select the mentioned value from the drop down). Please see the below code:

public class dropdown {
@Test
public void select(){
Keywords app = new Keywords();
app.openBrowser("Mozilla");
app.navigate("url");
app.select("lang", "Filipino");
}
}

Below is the keywords.java file code:
public class Keywords {

Properties prop =null;
WebDriver driver =null;

public Keywords(){
prop = new Properties();
FileInputStream fs;
try {
fs = new FileInputStream("C:\\dipti\\workspace\\Module9\\src\\Test.properties");
prop.load(fs);
} catch (Exception e) {
e.printStackTrace();
}
}

public void openBrowser(String browserType){
ProfilesIni profs = new ProfilesIni();
FirefoxProfile fp = profs.getProfile("sel");
driver = new FirefoxDriver(fp);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

}

public void navigate(String url){
System.out.println(prop.getProperty(url));
driver.get(prop.getProperty(url));


}

public void select(String xpath, String value){
driver.findElement(By.xpath(prop.getProperty(xpath))).sendKeys(value);
}
}

Below is the properties file code:
url=https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier
lang=//*[@id='lang-chooser']


M
Replied on 23/12/2015

use this

Keywords app = new Keywords();
app.openBrowser("Mozilla");
app.navigate("url");
app.select("lang", " ?Filipino? ");