Id’s Type casting Selenium

public By idReturn(String id){
id = id.toLowerCase();
if(id.startsWith(“id~”)) return By.id(id.replace(“id~”, “”));
else if(id.startsWith(“name~”)) return By.name(id.replace(“name~”, “”));
else if(id.startsWith(“cssselector~”)) return By.cssSelector(id.replace(“cssselector~”,    “”));
else if(id.startsWith(“xpath~”)) return By.xpath(id.replace(“xpath~”, “”));

return By.xpath(“Unable to find the element locater”);
}

public boolean enterText(String id, String value){
if(value.length() == 0) return false;
driver.findElement(idReturn(id)).clear();
driver.findElement(idReturn(id)).sendKeys(value);
return true;
}
public void clickElement(String id){
driver.findElement(idReturn(id)).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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s