Handling drop-down with Selenium

Selenium Select class is used to perform actions on drop-down:
Different functions provided by Select class:


selectByVisibleText()/deselectByVisibleText()
selects or deselects an option by its visible text from drop down
selectByValue()/deselectByValue()
selects or deselects an option by the value displayed for "value" attribute
selectByIndex()/deselectByIndex()
selects or deselects an option by its index
isMultiple()
returns TRUE if the drop-down allows multiple selection at a time and return FALSE if not allowed
deselectAll()
deselects all selected options



Sample Code:
WebElement dropdown = driver.findElement(By.name("dropdown"));
Select select = new Select(dropdown);

// Here we will perform the multiselect operation in the dropdown.
select.selectByVisibleText("John");

The project was not built since its build path is incomplete eclipse java maven

For those encountering this error while using Maven:

    Right click on the project, Build Path -> Configure Build Path...
    Select the libraries tab. If Maven dependencies is not in the list, you have identified the problem.
    Close the dialog.
    Right click on the project, Maven -> Disable Maven Nature
    Right click on the project, Configure -> Convert to Maven Project.

How to Drag and Drop by co-ordinates in Webdriver

 


    WebElement draggable3 = driver.findElement(By.id("ABC"));
        new Actions(driver).dragAndDropBy(draggable3, 400, 90).build().perform();

Check whether Javascript pop up displayed with Webdriver

public boolean isAlertPresent()
{
    try    {
        driver.switchTo().alert();
        return true;
    }   // try    catch (NoAlertPresentException Ex)
    {
        return false;
    }   // catch}
 
 
if(isAlertPresent()){
  driver.switchTo().alert().accept();
}