package com.property; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; public class Gbuttonproperty { private WebDriver driver; private String buttonText=null; private int buttonhight=0; public String buttontext(String locator,String Value) { if(locator=="xpath") { buttonText=driver.findElement(By.xpath(Value)).getText(); return buttonText; } else if(locator == "id") { buttonText = this.driver.findElement(By.id(Value)).getText(); return buttonText; } else if(locator=="name"){ String buttonText = this.driver.findElement(By.name(Value)).getText(); return buttonText; } else if(locator=="classname"){ String buttonText = this.driver.findElement(By.className(Value)).getText(); return buttonText; } else if(locator=="cssSelector"){ String buttonText =this.driver.findElement(By.cssSelector(Value)).getText(); return buttonText; } return null; } public int buttonhight(String locator,String Value){ if(locator== "xpath") { System.out.println("hello"); int buttonhight = driver.findElement(By.xpath(Value)).getSize().getHeight(); return buttonhight; } else if(locator == "id") { int buttonhight =this.driver.findElement(By.id(Value)).getSize().height; return buttonhight; } else if(locator=="name"){ int buttonhight = this.driver.findElement(By.name(Value)).getSize().getHeight(); return buttonhight; } else if(locator=="classname"){ int buttonhight = this.driver.findElement(By.className(Value)).getSize().getHeight(); return buttonhight; } else if(locator=="cssSelector"){ int buttonhight = this.driver.findElement(By.cssSelector(Value)).getSize().getHeight(); return buttonhight; } return 0; } } package com.properies; import com.property.Gbuttonproperty; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class Gbutton { private WebDriver driver; private String baseUrl; private Gbuttonproperty buttonproperty; //Gbuttonproperty b = new Gbuttonproperty(); @BeforeMethod public void start() throws Exception { baseUrl = "https://www.google.com/"; driver = new FirefoxDriver(); } @Test public void button(){ driver.get(baseUrl ); Gbuttonproperty b=new Gbuttonproperty(); b.buttonhight("xpath", "//*[@id='gbqfba']"); b=null; b.buttontext("xpath","id('gbqfba')"); b=null; } @AfterMethod public void tearDown() throws Exception { driver.quit(); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.