Selenium WebDriver Methods, Best Selenium WebDriver Methods, Course, Classes, Training Institute

Navigate to URL or Back or Forward in Selenium Webdriver – 1st command will navigate to specific URL, 2nd will navigate one step back and 3rd command will navigate one step forward.
Verify Element Present in Selenium WebDriver — It will return true if element is present on page, else it will return false in variable iselementpresent.
Boolean iselementpresent =driver.findElements(By.xpath(“//input[@id=’text2′]”)).size()!= 0;
Capturing entire page screenshot in Selenium WebDriver – It will capture page screenshot and store it in your D: drive.
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File(“D:\screenshot.jpg”));
Generating Mouse Hover Event In WebDriver– This will move mouse on targeted element.
Actions actions = new Actions(driver);
WebElement moveonmenu = driver.findElement(By.xpath(“//div[@id=’menu1′]/div”));
Handling Multiple Windows In Selenium WebDriver.
Get All Window Handles.—This will give you to get window handle and then how to switch from one window to another window.
Set AllWindowHandles = driver.getWindowHandles();
Extract parent and child window handle from all window handles.
String window1 = (String) AllWindowHandles.toArray()[0];
String window2 = (String) AllWindowHandles.toArray()[1];
Use window handle to switch from one window to other window.
Check Whether Element is Enabled Or Disabled In Selenium Web driver- This will verify that element (text box) fname is enabled or not. You can use it for any input element.
boolean fname = driver.findElement(By.xpath(“//input[@name=’fname’]”)).isEnabled(); System.out.print(fname);
Selenium WebDriver Assertions With TestNG Framework
Assert.assertEquals(actual, expected);
assertEquals assertion helps you to assert actual and expected equal values.
Assert.assertNotEquals(actual, expected);
assertNotEquals assertion is useful to assert not equal values.
assertTrue assertion works for boolean value true assertion.
assertFalse assertion works for boolean value false assertion.
Submit() method to submit form driver.findElement(By.xpath(“//input[@name=’Company’]”)).submit(); It will submit the form.
Handling Alert, Confirmation and Prompts Popups
String myalert = driver.switchTo().alert().getText(); To store alert text.
driver.switchTo().alert().accept(); To accept alert.
driver.switchTo().alert().dismiss(); To dismiss confirmation.
driver.switchTo().alert().sendKeys(“This Is John”); To type text In text box of prompt popup.
22.Handling DRAG and DROP
WebDriver d = new FirefoxDriver();
Actions a=new Actions(d);
23.Handling the frames in Webdriver
To Enter/Select the Frame – driver.switchTo().frame(“frameid/name / index”)
To Exit from Frame – driver.switchTo().defaultContent()
CALENDAR popups –/*IRCTC calendar*/
driver.findElement(“calendar_icon1”)).click(); driver.findElement(By.xpath(“//div[@id=’CalendarControl’]/table[tbody[tr[td[text()=’October 2012′]]]]/descendant::a[text()=’5′]”)).click();
Context Click (Right Click)
WebElement parentMenu = driver.findElement(By.linkText(“Tourist Trains”)); Actions act = new Actions(driver); //Create Action object for Driver act.contextClick(parentMenu).build().perform(); //Context Click act.sendKeys(Keys.ARROW_RIGHT).build().perform(); Thread.sleep(1000); act.sendKeys(Keys.ARROW_DOWN).build().perform(); Thread.sleep(1000); act.sendKeys(Keys.ENTER).build().perform();
Other Browser (Internet Explorer)
System.setProperty(“”,”D:l\browserdrivers\IEDriverServer.exe”); WebDriver driver =new InternetExplorerDriver();
Other Browser (Chrome)
System.setProperty(“”,”D:\browserdrivers\Chromedriver.exe”); WebDriver driver = new ChromeDriver();

Questions at

Share your love

Leave a Reply