Some Basic Selenium Web Driver Commands
| Sno. | User Action | Web Driver Commands | |
| 1 | Open Browser |
WebDriver
driver=new FirefoxDriver();
WebDriver
driver=new SafariDriver();
WebDriver
driver=new chromeDriver();
WebDriver
driver=new InternetExplorerDriver();
|
|
| 2 | Type URL in the browser |
|
driver.get("http://www.google.com"); |
| 3 | Find any element on the browser |
By Name
|
driver.findElement(By.name("Email"))
|
By id
|
driver.findElement(By.id("submitButton"))
|
||
By Xpath
|
driver.findElement(By.xpath("//*[@id='gbqfb']"))
|
||
| By Link | driver.findElement(By.linkText(t)) |
||
| By CSS selector | driver.findElement(By.cssSelector("a[title=\"Go
to Facebook Home\"]")) |
||
| By Partial Link Text |
driver.findElement(By.partialLinkText("Name")
|
||
| 4 | Click on any element | driver.findElement(By.id("submitButton")).click(); |
|
| 5 | Type from Keyboard | driver.findElement(By.name("Email")).sendKeys("a@a.com"); |
|
| 6 | Get Text | String gettingtext = driver.findElement(By.xpath("some xpath")).getText(); |
|
| 7 | Accepting alert | driver.findElement(By.xpath (“<Xpath>”)).click(); Alert alert = driver.switchTo().alert(); alert.accept(); |
|
| 8 | Move from 1 tab to another | driver.switchTo().window("windowName");
driver.switchTo().frame("frameName");
|
|
| 9 | Select Value from dropdown |
Select
customerdropdown = new Select(driver.findElement(By.id("selectedCustomer")));
customerdropdown.selectByVisibleText("testCustomer");
|
|
| 10 | Wait for some time |
Thread.sleep(5000);
|
|
| 11 | Implicit Wait |
driver.manage().timeouts().implicitlyWait(15,
TimeUnit.SECONDS);
|
|
| 12 | Explicit Wait |
WebElement waitForLoginText = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='firstpane']/form/p[1]/img")));
|
|
| 13 | Get Title |
driver.getTitle();
|
|
| 14 | Get Current URL |
driver.getCurrentUrl();
|
|
| 15 | Deselect value |
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByVisibleText("Russia");
|
|
| 16 | Browser back and forward navigation |
WebDriver driver= new FirefoxDriver();
driver.navigate().to("https://www.google.co.in/");
driver.findElement(By.id("gb_70")).click();
driver.navigate().back();
driver.navigate().forward();
|
|
| 17 | Maximize Browser |
driver.manage().window().maximize();
|
|
| 18 | Is element present |
Boolean iselementpresent =
driver.findElements(By.id("signIn")).size()!= 0;
|
|
| 19 | Mouse Hover |
Actions builder = new Actions(driver);
Action mouseOverHome =
builder.moveToElement(getObject("mmrfax_fab_rightmenu")).build();
mouseOverHome.perform();
|
|
| 20 | Close Browser (Close the current window, if there are multiple windows, it will close the current window which is active) | driver.close();
|
|
| 21 | Close all sessions of that browser |
driver.quit();
|
No comments:
Post a Comment