In this example we will create a Label in Gmail. Using TestNG framework in Selenium.
package Webdriverprgs; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Actions; import org.testng.annotations.Test; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest; import org.testng.annotations.Test; import org.testng.annotations.BeforeTest; import org.testng.annotations.AfterTest; public class createlabel { public WebDriver driver; public WebElement element; public Robot robot; public Actions actions; @Test public void f() throws InterruptedException, Exception { driver.findElement(By.id("Email")).sendKeys("jan30selenium"); driver.findElement(By.id("Passwd")).sendKeys("selenium1"); driver.findElement(By.id("signIn")).click(); Actions act=new Actions(driver); //Thread.sleep(20000); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); element=driver.findElement(By.xpath("html/body/div[7]/div[3]/div/div[2]/div[1]/div[1]/div[1]/div[2]")); actions=new Actions(driver); actions.moveToElement(element).build().perform(); driver.findElement(By.xpath(".//*[@id=':j2']/span[2]/div")).click(); WebElement element = driver.findElement(By.linkText("Create new label")); ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element); Thread.sleep(500); driver.findElement(By.linkText("Create new label")).click(); driver.findElement(By.cssSelector("input.xx")).sendKeys("Aditya"); driver.findElement(By.name("ok")).click(); } @BeforeTest public void beforeTest() { driver=new FirefoxDriver(); driver.get("http://gmail.com"); driver.manage().window().maximize(); } @AfterTest public void afterTest() { } }Copy this code your eclipse IDE and import the required libraries and go for test. Enjoy! Keep posting your comments.
ReplyDeleteYour blog is very nice,i would like to thank you for giving such kind of article.
Selenium Training in Chennai
Selenium Training Institute in Chennai
JAVA Training in Chennai
Python Training in Chennai
Hadoop Training in Chennai
Software testing training in chennai
Selenium Training in Annanagar
Awesome post. I am a normal visitor of your blog and appreciate you taking the time to maintain the excellent site. I’ll be a frequent visitor for a long time.
ReplyDeleteACP Sheet
ACP Sheet Price
Aluminium Composite Panel