0% found this document useful (0 votes)
60 views

Selenium Notes 09062021

The document discusses various Selenium WebDriver commands and strategies for automating web applications. It covers initializing the WebDriver, navigating to URLs, locating elements, interacting with elements by entering text, clicking buttons, clearing fields, and more. Element locators discussed include ID, name, class, tag name, link text, partial link text, CSS, and XPath. Handling drop-downs and performing drag and drop actions are also summarized.

Uploaded by

Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Selenium Notes 09062021

The document discusses various Selenium WebDriver commands and strategies for automating web applications. It covers initializing the WebDriver, navigating to URLs, locating elements, interacting with elements by entering text, clicking buttons, clearing fields, and more. Element locators discussed include ID, name, class, tag name, link text, partial link text, CSS, and XPath. Handling drop-downs and performing drag and drop actions are also summarized.

Uploaded by

Bharath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Selenium Webdriver:

we can access webdriver methods by using chromedriver class instantiate like below:

WebDriver driver = new ChromeDriver();


driver.getTitle();

Selenium Commands in WebDriver:

1.fetching a web page by using below methods:

using Get method:


driver.get("www.javatpoint.com");

Using Navigate Method:


driver.navigate().to("https://javatpoint.com/selenium-tutorial");

2.Locating forms and sending user inputs:

driver.findElement(By.id("lst-ib")).sendKeys("Java Tutorials");

3.Clearing User Inputs:

The clear() method is used to clear the user inputs from the text box.

driver.findElement(By.name("q")).clear();

4. Fetching data over any web element

Sometimes we need to fetch the text written over a web element for performing some
assertions and debugging. We use getText() method to fetch data written over any
web element.

driver.findElement(By.id("element567")).getText();

5. Performing Click event

The click() method is used to perform click operation on any web element.

driver.findElement(By.id("btnK")).click();

6. Navigating backward in browser history


driver.navigate().back();

7. Navigating forward in browser history


driver.navigate().forward();

8. Refresh/ Reload a web page


driver.navigate().refresh();

9. Closing Browser
driver.close();

10. Closing Browser and other all other windows associated with the driver
driver.quit();

11. Moving between Windows


driver.switchTo().window("windowName");
13. Moving between Frames
driver.switchTo().frame("frameName");

14. Drag and Drop


Drag and Drop operation is performed using the Action class.

WebElement element = driver.findElement(By.name("source"));


WebElement target = driver.findElement(By.name("target"));

(new Actions(driver)).dragAndDrop(element, target).perform();


Let us consider a sample test script which will cover most of the commonly used
WebDriver commands.

Selenium WebDriver- Locating Strategies:

WebDriver uses the same set of locating strategies for specifying location of a
particular web element.

A list of Locating Strategies used in WebDriver:

ByID -> driver.findElement(By.id(element ID));


By Name -> driver.findElement(By.name(element name));
By Class Name -> driver.findElement(By.className(elementclass));
By Tag Name -> driver.findElement(By.tagName(htmltagname));
By Link Text -> driver.findElement(By.linkText(linktext));
By Partial Link Text -> driver.findElement(By.partialLinkText(linktext));
By CSS -> driver.findElement(By.cssSelector(<cssSelector>))
By XPath -> driver.findElement(By.xpath(<xpath>)

Selenium WebDriver- Handling drop-downs

The 'Select' class in Selenium WebDriver is used for selecting and deselecting
option in a dropdown. The objects of Select type can be initialized by passing the
dropdown webElement as parameter to its constructor.

WebElement testDropDown = driver.findElement(By.id("testingDropdown"));


Select dropdown = new Select(testDropDown);

How to select an option from drop-down menu?

WebDriver provides three ways to select an option from the drop-down menu.
1. selectByIndex - It is used to select an option based on its index, beginning
with 0.
dropdown.selectByIndex(5);
2. selectByValue - It is used to select an option based on its 'value' attribute.
dropdown.selectByValue("Database");
3. selectByVisibleText - It is used to select an option based on the text over the
option.
dropdown.selectByVisibleText("Database Testing");

Selenium WebDriver- Drag and Drop

Actions in Selenium WebDriver


//WebElement on which drag and drop operation needs to be performed
WebElement from = driver.findElement(By.id("sourceImage"));

//WebElement to which the above object is dropped


WebElement to = driver.findElement(By.id("targetDiv"));
//Creating object of Actions class to build composite actions
Actions act = new Actions(driver);

//Performing the drag and drop action


act.dragAndDrop(from,to).build().perform();

You might also like